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>
closes#32240#32232
The main cause for the time out is the slow json encoding of large data.
In #32240 they tried to resolve the issue by reducing the size of the
test. However as Felix pointed out, the test is still kind of confusing.
I've refactored the test so it is more understandable and have reduced
the amount of data needed to be json encoded. I think it is still
important to ensure that the default read limit is not active, so I have
retained one large (~32 MB) test case, but it's at least smaller than
the existing ~64 MB test case.
Co-authored-by: lightclient <14004106+lightclient@users.noreply.github.com>
Exposing the public method to setReadLimits for Websocket RPC to
prevent OOM.
Current, Geth Server is using a default 32MB max read limit (message
size) for websocket, which is prune to being attacked for OOM. Any one
can easily launch a client to send a bunch of concurrent large request
to cause the node to crash for OOM. One example of such script that can
easily crash a Geth node running websocket server is like this:
ec830979ac/poc.go
---------
Co-authored-by: Yiming Zang <50607998+yzang2019@users.noreply.github.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
---
**Description:**
- Replaced outdated GitHub wiki links with current, official
documentation URLs.
- Removed links that redirect or are no longer relevant.
- Ensured all references point to up-to-date and reliable sources.
---
Co-authored-by: Maxim Evtush <154841002+maximevtush@users.noreply.github.com>
Similar to https://github.com/ethereum/go-ethereum/pull/31856, remove
the not availabe shh, swarm modules in the console.
---------
Co-authored-by: Zhou <DanialZhouMAX@gmail.com>
Co-authored-by: Gary Rong <garyrong0905@gmail.com>
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>
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>
Here we add distinct error messages for network timeouts and JSON parsing errors.
Note this specifically applies to HTTP connections serving a single RPC request.
Co-authored-by: zhiqiangxu <652732310@qq.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
* rpc: add more test cases for arg types #29006
* rpc: add more test cases for arg types #29006
---------
Co-authored-by: Andrei Kostakov <bps@dzen.ws>
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.
The String() version of BlockNumberOrHash uses decimal for all block numbers, including negative ones used to indicate labels. Switch to using BlockNumber.String() which encodes it correctly for use in the JSON-RPC API.
Co-authored-by: Adrian Sutton <adrian@oplabs.co>
This change adds a configurable limit to websocket message.
---------
Co-authored-by: tylerni7 <tylerni7@gmail.com>
Co-authored-by: Martin Holst Swende <martin@swende.se>
We're trying a new named pipe library, which should hopefully fix some occasional failures in CI.
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Felix Lange <fjl@twurst.com>
This should fix#27726. With enough load, it might happen that the SetPongHandler
callback gets invoked before the call to SetReadDeadline is made in pingLoop. When
this occurs, the socket will end up with a 30s read deadline even though it got the pong,
which will lead to a timeout.
The fix here is processing the pong on pingLoop, synchronizing with the code that
sends the ping.
Co-authored-by: Felix Lange <fjl@twurst.com>
Package rpc uses cgo to find the maximum UNIX domain socket path
length. If exceeded, a warning is printed. This is the only use of cgo in this
package. It seems excessive to depend on cgo just for this warning, so
we now hard-code the usual limit for Linux instead.
---------
Co-authored-by: Koichi Shiraishi <zchee.io@gmail.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
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>