Skip to content

Commit

Permalink
move readLoop to goroutine to avoid "too many open files"
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Jul 27, 2018
1 parent 8500fb6 commit cb39818
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ do
done
done

# Need to rebuild lthe inux-rethink binary without stripping debug info.
# Need to rebuild the linux-rethink binary without stripping debug info.
echo "Building the binary for the demo at api.tinode.co"

rm -f $GOPATH/bin/tinode
Expand Down
2 changes: 2 additions & 0 deletions loadtest/tinode.erl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
%% Support module for Tinode load testing with Tsung.
%% Compile using erlc then copy resulting .beam to
%% /usr/local/lib/erlang/lib/tsung-1.7.0/ebin/
%% Alternatively you can just leave it in the current
%% directory.

-module(tinode).
-export([rand_user_secret/1]).
Expand Down
9 changes: 7 additions & 2 deletions server/hdl_websock.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ func (sess *Session) readLoop() {
// Read a ClientComMessage
_, raw, err := sess.ws.ReadMessage()
if err != nil {
log.Println("sess.readLoop: " + err.Error())
if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway, websocket.CloseAbnormalClosure) {
log.Println("sess.readLoop: " + err.Error())
}
return
}

Expand Down Expand Up @@ -148,6 +150,9 @@ func serveWebSocket(wrt http.ResponseWriter, req *http.Request) {

sess := globals.sessionStore.Create(ws, "")

// Do work in goroutines to return from serveWebSocket() to release file pointers.
// Otherwise "too many open files" will happen.

go sess.writeLoop()
sess.readLoop()
go sess.readLoop()
}

0 comments on commit cb39818

Please sign in to comment.