grpc-websocket-proxy icon indicating copy to clipboard operation
grpc-websocket-proxy copied to clipboard

fix write concurrency to websocket

Open jkralik opened this issue 4 years ago • 1 comments

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 avatar Jul 14 '21 14:07 jkralik

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

OS-M avatar Feb 21 '23 12:02 OS-M