Skip to content

Move the NodeStream server to internal/stream#271

Closed
meling wants to merge 1 commit intomasterfrom
meling/269/move-server-to-stream-pkg
Closed

Move the NodeStream server to internal/stream#271
meling wants to merge 1 commit intomasterfrom
meling/269/move-server-to-stream-pkg

Conversation

@meling
Copy link
Member

@meling meling commented Feb 20, 2026

Move NodeStream handler to internal/stream

Motivation

As part of the ongoing refactor to consolidate stream infrastructure in
internal/stream, this PR moves the gRPC NodeStream implementation out
of the top-level gorums package and into a new internal/stream.Server
type.

Changes

New file: internal/stream/server.go

Introduces stream.Server, which implements the gRPC GorumsServer
interface. It owns the per-connection receive/send loop and mutex-based
request ordering, and dispatches each incoming message to a registered
MessageHandler callback:

type MessageHandler func(ctx context.Context, mut *sync.Mutex, finished chan<- *Message, msg *Message)

The callback design decouples NodeStream from gorums.Message, keeping
the stream package free of any dependency on gorums-level types.

Modified: server.go

  • Removes streamServer, newStreamServer(), and NodeStream().
  • Server.srv changes from *streamServer to *stream.Server.
  • RegisterHandler injects a MessageHandler closure that handles
    ServerCtx creation, request unmarshaling, gorums.Message wrapping,
    interceptor chaining, and response dispatch.

Design

The boundary is a callback: internal/stream owns the transport loop;
gorums owns the application-layer message handling. This preserves the
public API (gorums.Server, gorums.ServerCtx, gorums.Interceptor,
gorums.Handler, gorums.Message) with no changes to generated code or
user-facing types.

Testing

All existing tests pass. The two pre-existing failures in
TestChannelEnsureStream and TestChannelStreamReadyAfterReconnect are
unrelated to this change.

Fixes #269

@deepsource-io
Copy link
Contributor

deepsource-io bot commented Feb 20, 2026

DeepSource Code Review

We reviewed changes in 5f902d5...38e105c on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
Go Feb 24, 2026 7:14p.m. Review ↗
Shell Feb 24, 2026 7:14p.m. Review ↗

@meling meling changed the base branch from master to meling/268/move-channel-to-stream-pkg February 20, 2026 07:49
Base automatically changed from meling/268/move-channel-to-stream-pkg to master February 21, 2026 17:02
Extract the gRPC NodeStream implementation from the gorums package into
a new internal/stream.Server type, keeping only the public API surface
(Server, ServerCtx, Interceptor, Handler) in the gorums package.

Introduce a MessageHandler callback type in the stream package so that
NodeStream can remain decoupled from gorums.Message. The gorums package
wires this callback in RegisterHandler: it creates the ServerCtx, unmarshals
the request, wraps it in a gorums.Message, runs the interceptor chain,
and dispatches the response — all without the stream package needing to
know about gorums-level types.

stream/server.go adds:
- Server struct (implements GorumsServer via NodeStream)
- MessageHandler callback type
- NewServer(), RegisterHandler()

server.go removes:
- streamServer struct, newStreamServer(), NodeStream() (~80 lines)
- gorums.Server.srv changes from *streamServer to *stream.Server
- RegisterHandler now injects the gorums.Message wrapping callback
@meling meling force-pushed the meling/269/move-server-to-stream-pkg branch from ea6ac9e to 38e105c Compare February 24, 2026 19:14
@meling
Copy link
Member Author

meling commented Feb 26, 2026

Superseded by #278

@meling meling closed this Feb 26, 2026
@meling meling deleted the meling/269/move-server-to-stream-pkg branch February 26, 2026 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore: split server.go between the gorums package and the internal/stream package

1 participant