Skip to content

Commit

Permalink
Merge pull request #215 from xiangli-cmu/fix_channel_race
Browse files Browse the repository at this point in the history
fix(server.go) check server state before send event to channel
  • Loading branch information
xiang90 committed Apr 10, 2014
2 parents 72bb1cd + b6b4e57 commit 3b1dea1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,10 @@ func (s *server) loop() {
// Sends an event to the event loop to be processed. The function will wait
// until the event is actually processed before returning.
func (s *server) send(value interface{}) (interface{}, error) {
if !s.Running() {
return nil, StopError
}

event := &ev{target: value, c: make(chan error, 1)}
select {
case s.c <- event:
Expand All @@ -630,6 +634,10 @@ func (s *server) send(value interface{}) (interface{}, error) {
}

func (s *server) sendAsync(value interface{}) {
if !s.Running() {
return
}

event := &ev{target: value, c: make(chan error, 1)}
// try a non-blocking send first
// in most cases, this should not be blocking
Expand Down

0 comments on commit 3b1dea1

Please sign in to comment.