cloudflared-mirror/websocket
Benjamin Buzbee 452f8cef79
Allow partial reads from a GorillaConn; add SetDeadline (from net.Conn) (#330)
* Allow partial reads from a GorillaConn; add SetDeadline (from net.Conn)

The current implementation of GorillaConn will drop data if the
websocket frame isn't read 100%. For example, if a websocket frame is
size=3, and Read() is called with a []byte of len=1, the 2 other bytes
in the frame are lost forever.

This is currently masked by the fact that this is used primarily in
io.Copy to another socket (in ingress.Stream) - as long as the read buffer
used by io.Copy is big enough (it is 32*1024, so in theory we could see
this today?) then data is copied over to the other socket.

The client then can do partial reads just fine as the kernel will take
care of the buffer from here on out.

I hit this by trying to create my own tunnel and avoiding
ingress.Stream, but this could be a real bug today I think if a
websocket frame bigger than 32*1024 was received, although it is also
possible that we are lucky and the upstream size which I haven't checked
uses a smaller buffer than that always.

The test I added hangs before my change, succeeds after.

Also add SetDeadline so that GorillaConn fully implements net.Conn

* Comment formatting; fast path

* Avoid intermediate buffer for first len(p) bytes; import order
2021-03-09 19:57:04 +04:00
..
connection.go Allow partial reads from a GorillaConn; add SetDeadline (from net.Conn) (#330) 2021-03-09 19:57:04 +04:00
notice_page.go AUTH-2169 make access login page more generic 2020-06-08 11:20:30 -05:00
websocket.go Allow partial reads from a GorillaConn; add SetDeadline (from net.Conn) (#330) 2021-03-09 19:57:04 +04:00
websocket_test.go Allow partial reads from a GorillaConn; add SetDeadline (from net.Conn) (#330) 2021-03-09 19:57:04 +04:00