Skip to content

Commit 26725df

Browse files
committed
fixup! Ensure message order with a buffer
1 parent ae56de6 commit 26725df

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

websocket_js.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ func (c *Conn) read(ctx context.Context) (MessageType, []byte, error) {
113113
defer c.readBufMu.Unlock()
114114

115115
me := c.readBuf[0]
116+
// Ensures GC can collect the message event.
117+
c.readBuf[0] = wsjs.MessageEvent{}
118+
// We do not shrink the array since it will be resized
119+
// as appropriate by append in the OnMessage callback.
116120
c.readBuf = c.readBuf[1:]
117121

118122
if len(c.readBuf) > 0 {

0 commit comments

Comments
 (0)