summaryrefslogtreecommitdiff
path: root/irc
diff options
context:
space:
mode:
authorHubert Hirtz <hubert@hirtz.pm>2020-11-22 22:22:23 +0100
committerHubert Hirtz <hubert@hirtz.pm>2020-11-23 10:50:37 +0100
commit2221f9343619d8ddf662995b517304628f947d0b (patch)
treee1cc03fc11b90918e75cc42058540a520df9fe99 /irc
parentDocument the IRC library (diff)
Cleanly stop all coroutines on irc.Session.Stop
This fixes a panic when irc.Session.handle is called with an empty message.
Diffstat (limited to 'irc')
-rw-r--r--irc/states.go16
-rw-r--r--irc/typing.go8
2 files changed, 19 insertions, 5 deletions
diff --git a/irc/states.go b/irc/states.go
index 7722d20..dcfff1f 100644
--- a/irc/states.go
+++ b/irc/states.go
@@ -260,6 +260,7 @@ func (s *Session) Stop() {
close(s.acts)
close(s.evts)
close(s.msgs)
+ s.typings.Stop()
}
// Poll returns the event channel where incoming events are reported.
@@ -465,7 +466,10 @@ func (s *Session) run() {
var err error
select {
- case act := <-s.acts:
+ case act, ok := <-s.acts:
+ if !ok {
+ break
+ }
switch act := act.(type) {
case actionSendRaw:
err = s.sendRaw(act)
@@ -484,13 +488,19 @@ func (s *Session) run() {
case actionRequestHistory:
err = s.requestHistory(act)
}
- case msg := <-s.msgs:
+ case msg, ok := <-s.msgs:
+ if !ok {
+ break
+ }
if s.registered {
err = s.handle(msg)
} else {
err = s.handleStart(msg)
}
- case t := <-s.typings.Stops():
+ case t, ok := <-s.typings.Stops():
+ if !ok {
+ break
+ }
s.evts <- TagEvent{
User: s.users[t.Name].Name,
Target: s.channels[t.Target].Name,
diff --git a/irc/typing.go b/irc/typing.go
index a62a420..28fb223 100644
--- a/irc/typing.go
+++ b/irc/typing.go
@@ -24,8 +24,7 @@ func NewTypings() *Typings {
stops: make(chan Typing, 16),
}
go func() {
- for {
- t := <-ts.timeouts
+ for t := range ts.timeouts {
now := time.Now()
ts.l.Lock()
oldT, ok := ts.targets[t]
@@ -41,6 +40,11 @@ func NewTypings() *Typings {
return ts
}
+func (ts *Typings) Stop() {
+ close(ts.timeouts)
+ close(ts.stops)
+}
+
func (ts *Typings) Stops() <-chan Typing {
return ts.stops
}