{"record":{"id":"47cf69bd517507e1","repo":"apache/beam","slug":"error-creating-jetstream-context-v","errorCode":null,"errorMessage":"error creating JetStream context: %v","messagePattern":"error creating JetStream context: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/io/natsio/common.go","lineNumber":51,"sourceCode":"func (fn *natsFn) Setup() error {\n\tif fn.nc != nil && fn.js != nil {\n\t\treturn nil\n\t}\n\n\tvar opts []nats.Option\n\tif fn.CredsFile != \"\" {\n\t\topts = append(opts, nats.UserCredentials(fn.CredsFile))\n\t}\n\n\tconn, err := nats.Connect(fn.URI, opts...)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error connecting to NATS: %v\", err)\n\t}\n\tfn.nc = conn\n\n\tjs, err := jetstream.New(fn.nc)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error creating JetStream context: %v\", err)\n\t}\n\tfn.js = js\n\n\treturn nil\n}\n\nfunc (fn *natsFn) Teardown() {\n\tif fn.nc != nil {\n\t\tfn.nc.Close()\n\t}\n}\n","sourceCodeStart":33,"sourceCodeEnd":63,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/natsio/common.go#L33-L63","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nnats-server -p 4222 // JetStream disabled\n// after\nnats-server -p 4222 -js // JetStream enabled so jetstream.New succeeds","handlingStrategy":"validation","validationCode":"// pre-flight: verify JetStream is enabled on the target server\ninfo, err := nc.ServerInfo()\nif err == nil && !info.JetStream {\n\treturn errors.New(\"target NATS server has JetStream disabled; enable -js before running\")\n}","typeGuard":null,"tryCatchPattern":"js, err := jetstream.New(nc)\nif err != nil {\n\treturn fmt.Errorf(\"JetStream unavailable: %w (check server runs with JetStream enabled and version matches nats.go)\", err)\n}","preventionTips":["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"],"tags":["nats","jetstream","configuration","beam-io"],"backgroundTag":"feature-not-enabled","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}