Commit graph

12 commits

Author SHA1 Message Date
Daniel Liu
0c306686bb
rpc: fix limitedBuffer.Write to properly enforce size limit (#33545) (#1948)
Updated the `avail` calculation to correctly compute remaining capacity:
`buf.limit - len(buf.output)`, ensuring the buffer never exceeds its
configured limit regardless of how many times `Write()` is called.

Co-authored-by: Maxim Evtush <154841002+maximevtush@users.noreply.github.com>
2026-01-19 12:13:15 +05:30
Daniel Liu
5081beee0e
rpc: add method name length limit #31711 (#1406)
This change adds a limit for RPC method names to prevent potential abuse
where large method names could lead to large response sizes.

The limit is enforced in:
- handleCall for regular RPC method calls
- handleSubscribe for subscription method calls

Added tests in websocket_test.go to verify the length limit
functionality for both regular method calls and subscriptions.

---------

Co-authored-by: Matus Kysel <MatusKysel@users.noreply.github.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
2025-09-03 15:39:40 +08:00
Daniel Liu
445d9b37d3
rpc: truncate call error data logs #30028 (#1017)
Co-authored-by: Ceyhun Onur <ceyhun.onur@avalabs.org>
Co-authored-by: Felix Lange <fjl@twurst.com>
2025-04-29 17:14:14 +08:00
Daniel Liu
a4aebd5d88
rpc: fix typos (#1011) 2025-04-29 17:07:10 +08:00
Daniel Liu
5e4c2cb821
rpc: add method to test for subscription support #25942 (#999)
This adds two ways to check for subscription support. First, one can now check
whether the transport method (HTTP/WS/etc.) is capable of subscriptions using
the new Client.SupportsSubscriptions method.

Second, the error returned by Subscribe can now reliably be tested using this
pattern:

    sub, err := client.Subscribe(...)
    if errors.Is(err, rpc.ErrNotificationsUnsupported) {
        // no subscription support
    }

---------

Co-authored-by: zhiqiangxu <652732310@qq.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
2025-04-28 17:46:24 +08:00
Daniel Liu
c75623ace7
rpc: add limit for batch request and response size #26681 (#998) 2025-04-28 17:00:30 +08:00
Daniel Liu
58e9b8c8f6
node, rpc: improve HTTP write timeout handling #25457 (#982)
Here we add special handling for sending an error response when the write timeout of the
HTTP server is just about to expire. This is surprisingly difficult to get right, since is
must be ensured that all output is fully flushed in time, which needs support from
multiple levels of the RPC handler stack:

The timeout response can't use chunked transfer-encoding because there is no way to write
the final terminating chunk. net/http writes it when the topmost handler returns, but the
timeout will already be over by the time that happens. We decided to disable chunked
encoding by setting content-length explicitly.

Gzip compression must also be disabled for timeout responses because we don't know the
true content-length before compressing all output, i.e. compression would reintroduce
chunked transfer-encoding.

Co-authored-by: Sina Mahmoodi <1591639+s1na@users.noreply.github.com>
2025-04-25 08:01:44 +08:00
Daniel Liu
02eb1d5375
rpc: improve error codes for internal server errors #25678 (#974)
This changes the error code returned by the RPC server in certain situations:

- handler panic: code -32603
- result marshaling error: code -32603
- attempt to subscribe via HTTP: code -32001

In all of the above cases, the server previously returned the default error
code -32000.

Co-authored-by: Nicholas <nicholas.zhaoyu@gmail.com>
Co-authored-by: Nicholas Zhao <nicholas.zhao@gmail.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
2025-04-24 19:03:29 +08:00
Daniel Liu
e7ca47c280
rpc: fix time key collision for logger with json output #24112 (#963)
The "t" key overrides the log message time in JSON output.

Co-authored-by: Roman Mazalov <83914728+gopherxyz@users.noreply.github.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
2025-04-24 18:35:18 +08:00
Daniel Liu
9f504a6243
rpc: tighter shutdown synchronization in client subscription #22597 (#955)
This fixes a rare issue where the client subscription forwarding loop
would attempt send on the subscription's channel after Unsubscribe has
returned, leading to a panic if the subscription channel was already
closed by the user. Example:

    sub, _ := client.Subscribe(..., channel, ...)
    sub.Unsubscribe()
    close(channel)

The race occurred because Unsubscribe called quitWithServer to tell the
forwarding loop to stop sending on sub.channel, but did not wait for the
loop to actually come down. This is fixed by adding an additional channel
to track the shutdown, on which Unsubscribe now waits.

Fixes #22322

Co-authored-by: Felix Lange <fjl@twurst.com>
2025-04-24 18:17:45 +08:00
Daniel Liu
2e34afe400 rpc: swap out timer metrics to histograms (#25044) 2024-12-13 14:00:12 +08:00
Banana-J
39f6e6ee56
upgrade the websocket in xdpos (#349) 2023-11-06 15:37:14 +11:00