Skip to content

Conversation

jkralik
Copy link

@jkralik jkralik commented Jul 14, 2021

according to https://pkg.go.dev/github.com/gorilla/websocket#hdr-Concurrency, concurrency is not supported by WriteMessage.

fixes issue with nginx proxy: SSL routines:ssl3_get_record:decryption failed or bad record mac

jkralik added 2 commits July 14, 2021 16:10
according to https://pkg.go.dev/github.com/gorilla/websocket#hdr-Concurrency, is not supported by WriteMessage.

fixes issue with nginx proxy: SSL routines:ssl3_get_record:decryption failed or bad record mac
fix write concurrency to socket
@OS-M
Copy link

OS-M commented Feb 21, 2023

Hi! Thank you for contributing and fixing that concurrency bug but unfortunately your solution introduces another one.
As scanner.Bytes() returns Go slice (aka pointer to an array) it can be overwritten by another call to scanner.Scan() which ends up with corrupting data inside the chan before it is written to the conn by another goroutine.
The solution here is to copy the array before adding it to the chan:

dataToWrite := make([]byte, len(scanner.Bytes()))
copy(dataToWrite, scanner.Bytes())
dataWriteChan <- dataToWrite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants