Commit graph

16 commits

Author SHA1 Message Date
Daniel Liu
266cf85510
rpc: remove deprecated method Notifier.Closed #29162 (#1022)
Co-authored-by: Undefinedor <wanghao@imwh.net>
2025-05-06 09:44:20 +08:00
Daniel Liu
d955e17cd6
rpc: add timeout to rpc client Unsubscribe #30318 (#1019)
Fixes #30156

This adds a repro of the linked issue. I fixed it by adding a timeout
when issuing the call to unsubscribe.

Co-authored-by: lightclient <14004106+lightclient@users.noreply.github.com>
2025-04-29 17:26:34 +08:00
Daniel Liu
a4aebd5d88
rpc: fix typos (#1011) 2025-04-29 17:07:10 +08:00
Delweng
7bf5517cda rpc: improve performance of subscription notification encoding #28328
It turns out that encoding json.RawMessage is slow because
package json basically parses the message again to ensure it is valid.
We can avoid the slowdown by encoding the entire RPC notification once,
which yields a 30% speedup.
2025-04-29 17:04:50 +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
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
716e58388f
rpc: fix godoc #24488 (#966)
Co-authored-by: s7v7nislands <s7v7nislands@gmail.com>
Co-authored-by: seven <seven@nodereal.io>
2025-04-24 18:38:38 +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
Banana-J
39f6e6ee56
upgrade the websocket in xdpos (#349) 2023-11-06 15:37:14 +11:00
olumuyiwadad
571c41f891 FIx Bad block error. 2021-09-17 17:59:06 +05:30
Felix Lange
4e474c74dc
rpc: fix subscription corner case and speed up tests (#17874)
Notifier tracks whether subscription are 'active'. A subscription
becomes active when the subscription ID has been sent to the client. If
the client sends notifications in the request handler before the
subscription becomes active they are dropped. The tests tried to work
around this problem by always waiting 5s before sending the first
notification.

Fix it by buffering notifications until the subscription becomes active.
This speeds up all subscription tests.

Also fix TestSubscriptionMultipleNamespaces to wait for three messages
per subscription instead of six. The test now finishes just after all
notifications have been received and doesn't hit the 30s timeout anymore.
2018-10-09 16:34:24 +02:00
Egon Elbre
e063d538b8 rpc: fix megacheck warnings 2017-08-08 11:08:37 +02:00
Bas van Kervel
37e3f561f1
rpc: support subscriptions under custom namespaces 2017-04-25 11:13:22 +02:00
Felix Lange
c213fd1fd8 all: import "context" instead of "golang.org/x/net/context"
There is no need to depend on the old context package now that the
minimum Go version is 1.7. The move to "context" eliminates our weird
vendoring setup. Some vendored code still uses golang.org/x/net/context
and it is now vendored in the normal way.

This change triggered new vet checks around context.WithTimeout which
didn't fire with golang.org/x/net/context.
2017-03-22 20:49:15 +01:00
Péter Szilágyi
18c77744ff
all: fix spelling errors 2017-01-06 19:44:35 +02:00
Bas van Kervel
47ff813012 rpc: refactor subscriptions and filters 2016-08-17 12:59:58 +02:00