Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check ws max send buffer size over time #1719

Merged
merged 1 commit into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/src/installation/command_line.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ Signal K Server provides the following command line options and environment vari
| `PLUGINS_WITH_UPDATE_DISABLED` | A comma separated list of plugin that will not be updated. |
| `SECURITYSTRATEGY` | Override the security strategy module name. |
| `WSCOMPRESSION` | Compress websocket messages _(default is false)_. |
| `MAXSENDBUFFERSIZE` | The maximum number of bytes allowed in the server's send buffer of a WebSocket connection. The connection will be terminated if this is exceeded. Guards against slow or dysfunctional clients that can not cope with the message volume _(default is 512 * 1024 bytes)_. |
| `MAXSENDBUFFERSIZE` | The maximum number of bytes allowed in the server's send buffer of a WebSocket connection. The connection will be terminated if this is exceeded for MAXSENDBUFFERCHECKTIME milliseconds. Guards against slow or dysfunctional clients that can not cope with the message volume _(default is 512 * 1024 bytes)_. |
| `MAXSENDBUFFERCHECKTIME` | The maximum number of bytes allowed in the server's send buffer of a WebSocket connection. The connection will be terminated if this is exceeded. Guards against slow or dysfunctional clients that can not cope with the message volume _(default is 512 * 1024 bytes)_. |
| `SIGNALK_SERVER_IS_UPDATABLE` | Allows the server to be updated through the GUI even if it is not installed in the standard paths _(default is false)_. If set to true, the server must have been installed with `npm install -g signalk-server`. |
| `SIGNALK_DISABLE_SERVER_UPDATES` | Disables server updates in the GUI _(default is false)_. |
| `DEBUG` | A comma-separated list of tags for debugging the specified module _(e.g signalk-server*,signalk-provider-tcp)_. Can now be defined directly in the graphical interface. More help on how to use the debug here: `https://www.npmjs.com/package/debug#wildcards` |
Expand Down
25 changes: 21 additions & 4 deletions src/interfaces/ws.js
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,10 @@ function startServerLog(app, spark) {
function getAssertBufferSize(config) {
const MAXSENDBUFFERSIZE =
process.env.MAXSENDBUFFERSIZE || config.maxSendBufferSize || 4 * 512 * 1024
const MAXSENDBUFFERCHECKTIME =
process.env.MAXSENDBUFFERCHECKTIME ||
config.maxSendBufferCheckTime ||
30 * 1000
debug(`MAXSENDBUFFERSIZE:${MAXSENDBUFFERSIZE}`)

if (MAXSENDBUFFERSIZE === 0) {
Expand All @@ -745,10 +749,23 @@ function getAssertBufferSize(config) {
return (spark) => {
debug(spark.id + ' ' + spark.request.socket.bufferSize)
if (spark.request.socket.bufferSize > MAXSENDBUFFERSIZE) {
spark.end({
errorMessage: 'Server outgoing buffer overflow, terminating connection'
})
console.error('Send buffer overflow, terminating connection ' + spark.id)
if (!spark.bufferSizeExceeded) {
console.warn(
`${spark.id} outgoing buffer > max:${spark.request.socket.bufferSize}`
)
spark.bufferSizeExceeded = Date.now()
}
if (Date.now() - spark.bufferSizeExceeded > MAXSENDBUFFERCHECKTIME) {
spark.end({
errorMessage:
'Server outgoing buffer overflow, terminating connection'
})
console.error(
'Send buffer overflow, terminating connection ' + spark.id
)
}
} else {
spark.bufferSizeExceeded = undefined
}
}
}