transport.go: disable stdio batching for newer protocols (#453)
This PR disables batching support for stdio by storing the negotiated protocol version and comparing it to protocolVersion20250618. Fixes: #21
This commit is contained in:
parent
bf3ff50a16
commit
b66679350e
1 changed files with 49 additions and 5 deletions
|
|
@ -283,6 +283,8 @@ func (r rwc) Close() error {
|
|||
//
|
||||
// See [msgBatch] for more discussion of message batching.
|
||||
type ioConn struct {
|
||||
protocolVersion string // negotiated version, set during session initialization.
|
||||
|
||||
writeMu sync.Mutex // guards Write, which must be concurrency safe.
|
||||
rwc io.ReadWriteCloser // the underlying stream
|
||||
|
||||
|
|
@ -360,6 +362,17 @@ func newIOConn(rwc io.ReadWriteCloser) *ioConn {
|
|||
|
||||
func (c *ioConn) SessionID() string { return "" }
|
||||
|
||||
func (c *ioConn) sessionUpdated(state ServerSessionState) {
|
||||
protocolVersion := ""
|
||||
if state.InitializeParams != nil {
|
||||
protocolVersion = state.InitializeParams.ProtocolVersion
|
||||
}
|
||||
if protocolVersion == "" {
|
||||
protocolVersion = protocolVersion20250326
|
||||
}
|
||||
c.protocolVersion = negotiatedVersion(protocolVersion)
|
||||
}
|
||||
|
||||
// addBatch records a msgBatch for an incoming batch payload.
|
||||
// It returns an error if batch is malformed, containing previously seen IDs.
|
||||
//
|
||||
|
|
@ -458,6 +471,10 @@ func (t *ioConn) Read(ctx context.Context) (jsonrpc.Message, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if batch && t.protocolVersion >= protocolVersion20250618 {
|
||||
return nil, fmt.Errorf("JSON-RPC batching is not supported in %s and later (request version: %s)", protocolVersion20250618, t.protocolVersion)
|
||||
}
|
||||
|
||||
t.queue = msgs[1:]
|
||||
|
||||
if batch {
|
||||
|
|
|
|||
Loading…
Reference in a new issue