From 474106a757beb9ad87805ee2b480691abcc947f3 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Mon, 18 Nov 2013 16:37:28 -0500 Subject: [PATCH] Sending and receving from chans on the same goroutine is a bad idea. --- sockets.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/sockets.go b/sockets.go index c0323b1..f748496 100644 --- a/sockets.go +++ b/sockets.go @@ -131,10 +131,17 @@ func (s *server) handleRPCRequest(w http.ResponseWriter, r *http.Request) { log.Errorf("RPCS: Error getting JSON message: %v", err) } + done := make(chan struct{}) + go func() { + if _, err := w.Write(<-frontend); err != nil { + log.Warnf("RPCS: could not respond to RPC request: %v", + err) + } + close(done) + }() + ProcessFrontendMsg(frontend, body, false) - if _, err := w.Write(<-frontend); err != nil { - log.Warnf("RPCS: could not respond to RPC request: %v", err) - } + <-done } // frontendListenerDuplicator listens for new wallet listener channels