diff options
author | Bjørn Erik Pedersen <[email protected]> | 2017-04-30 01:10:03 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2017-04-30 01:10:57 +0200 |
commit | 355736ec357c81dfb2eb6851ee019d407090c5ec (patch) | |
tree | 7d9b57369b7e43effb3fb193dedb8a84f419dbc6 /livereload/connection.go | |
parent | 93a447c5dd053e1c934036a66ebd05b95250a1d1 (diff) | |
download | hugo-355736ec357c81dfb2eb6851ee019d407090c5ec.tar.gz hugo-355736ec357c81dfb2eb6851ee019d407090c5ec.zip |
livereload: Fix data race in close
Fixes #2625
Diffstat (limited to 'livereload/connection.go')
-rw-r--r-- | livereload/connection.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/livereload/connection.go b/livereload/connection.go index 6e31b1baf..4e94e2ee0 100644 --- a/livereload/connection.go +++ b/livereload/connection.go @@ -15,6 +15,7 @@ package livereload import ( "bytes" + "sync" "github.com/gorilla/websocket" ) @@ -25,6 +26,16 @@ type connection struct { // Buffered channel of outbound messages. send chan []byte + + // There is a potential data race, especially visible with large files. + // This is protected by synchronisation of the send channel's close. + closer sync.Once +} + +func (c *connection) close() { + c.closer.Do(func() { + close(c.send) + }) } func (c *connection) reader() { |