moby / vpnkit

A toolkit for embedding VPN capabilities in your application
Apache License 2.0
1.11k stars 190 forks source link

go: avoid possible overflow of the Write window #619

Closed djs55 closed 1 year ago

djs55 commented 1 year ago

The Write window is used to keep track of how much buffer space is free in the remote to avoid one connection blocking the rest. Previously we checked the window and decided how much to write, then dropped the metadata mutex before performing the write. In theory another Write call on the same connection could see that buffer size is free, send too much and block the connection.

Therefore Write should take ownership of the space by bumping the current window before dropping the lock.