Skip to content

Commit

Permalink
fix: ws errors should conform to jsonrpc spec (#2505)
Browse files Browse the repository at this point in the history
* fix: ws errors should conform to jsonrpc spec

Signed-off-by: Ted Yeh <ted.yeh@validationcloud.io>

* Update packages/ws-server/src/metrics/connectionLimiter.ts

Co-authored-by: Logan Nguyen <logan@quiet-node.dev>
Signed-off-by: ted-yeh-vc <135632178+ted-yeh-vc@users.noreply.github.com>

* Update packages/ws-server/src/metrics/connectionLimiter.ts

Co-authored-by: Logan Nguyen <logan@quiet-node.dev>
Signed-off-by: ted-yeh-vc <135632178+ted-yeh-vc@users.noreply.github.com>

* Update packages/ws-server/src/metrics/connectionLimiter.ts

Co-authored-by: Logan Nguyen <logan@quiet-node.dev>
Signed-off-by: ted-yeh-vc <135632178+ted-yeh-vc@users.noreply.github.com>

---------

Signed-off-by: Ted Yeh <ted.yeh@validationcloud.io>
Signed-off-by: ted-yeh-vc <135632178+ted-yeh-vc@users.noreply.github.com>
Co-authored-by: Logan Nguyen <logan@quiet-node.dev>
  • Loading branch information
ted-yeh-vc and quiet-node authored May 23, 2024
1 parent c6cfd6c commit c4dac63
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions packages/ws-server/src/metrics/connectionLimiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,14 @@ export default class ConnectionLimiter {
ctx.websocket.send(
JSON.stringify({
jsonrpc: '2.0',
error: `Closing current connection due to exceeded maximum connections (max_con=${MAX_CONNECTION_LIMIT})`,
error: {
code: CONNECTION_LIMIT_EXCEEDED.code,
message: CONNECTION_LIMIT_EXCEEDED.message,
data: {
message: CONNECTION_LIMIT_EXCEEDED.message,
max_connection: MAX_CONNECTION_LIMIT,
},
},
id: '1',
}),
);
Expand All @@ -152,7 +159,14 @@ export default class ConnectionLimiter {
ctx.websocket.send(
JSON.stringify({
jsonrpc: '2.0',
error: `Closing current connection due to exceeded maximum connections from a single IP: address ${ip} - ${this.clientIps[ip]} connections. (max_con=${MAX_CONNECTION_LIMIT_PER_IP})`,
error: {
code: CONNECTION_IP_LIMIT_EXCEEDED.code,
message: CONNECTION_IP_LIMIT_EXCEEDED.message,
data: {
message: CONNECTION_IP_LIMIT_EXCEEDED.message,
max_connection: MAX_CONNECTION_LIMIT_PER_IP,
},
},
id: '1',
}),
);
Expand Down Expand Up @@ -188,7 +202,14 @@ export default class ConnectionLimiter {
websocket.send(
JSON.stringify({
jsonrpc: '2.0',
error: `Closing current connection due to reaching TTL (${maxInactivityTTL}ms)`,
error: {
code: TTL_EXPIRED.code,
message: TTL_EXPIRED.message,
data: {
message: TTL_EXPIRED.message,
max_inactivity_TTL: maxInactivityTTL,
},
},
id: '1',
}),
);
Expand Down

0 comments on commit c4dac63

Please sign in to comment.