apache/beam · error
error creating JetStream context
Error message
error creating JetStream context: %v
What it means
After connecting, Setup calls jetstream.New(fn.nc) to create a JetStream context on the NATS connection. If JetStream cannot be initialized on that connection, the error is wrapped with this message and Setup fails. This means the connected NATS server does not have JetStream enabled or the new jetstream API is unavailable.
Solutions
- Enable JetStream on the server (start nats-server with -js / jetstream { store_dir: ... })
- Upgrade the NATS server to a version compatible with the nats.go jetstream package
- Pin your nats.go dependency to match the server's JetStream API generation
- Confirm the connection stays alive between nats.Connect and jetstream.New
Example fix
// before nats-server -p 4222 // JetStream disabled // after nats-server -p 4222 -js // JetStream enabled so jetstream.New succeeds
Defensive patterns
Strategy: validation
Validate before calling
// pre-flight: verify JetStream is enabled on the target server
info, err := nc.ServerInfo()
if err == nil && !info.JetStream {
return errors.New("target NATS server has JetStream disabled; enable -js before running")
} Try / catch
js, err := jetstream.New(nc)
if err != nil {
return fmt.Errorf("JetStream unavailable: %w (check server runs with JetStream enabled and version matches nats.go)", err)
} Prevention
- Deploy nats-server with JetStream enabled (-js) in every environment the pipeline targets
- Keep nats.go and nats-server versions aligned (JetStream API generations)
- Pin the server version in deployment configs for reproducibility
- Document the JetStream requirement next to the NATS connection settings
When it happens
Trigger: jetstream.New(fn.nc) returns an error: JetStream is disabled on the NATS server, the server version predates the built-in JetStream API used by the nats.go jetstream package, or the connection is already closed.
Common situations: Connecting to a NATS server started without --js (JetStream disabled); old NATS server version incompatible with the nats.go jetstream package; server losing the connection right after connect.
Related errors
- error creating growable tracker
- error getting last message
- error getting stream
- consumerPollingTimeout should be > 0.
- err
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/47cf69bd517507e1.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/io/natsio/common.go:51
func (fn *natsFn) Setup() error {
if fn.nc != nil && fn.js != nil {
return nil
}
var opts []nats.Option
if fn.CredsFile != "" {
opts = append(opts, nats.UserCredentials(fn.CredsFile))
}
conn, err := nats.Connect(fn.URI, opts...)
if err != nil {
return fmt.Errorf("error connecting to NATS: %v", err)
}
fn.nc = conn
js, err := jetstream.New(fn.nc)
if err != nil {
return fmt.Errorf("error creating JetStream context: %v", err)
}
fn.js = js
return nil
}
func (fn *natsFn) Teardown() {
if fn.nc != nil {
fn.nc.Close()
}
}
View on GitHub (pinned to 12126d8942)