{"record":{"id":"9eae22e40c11a58e","repo":"nautechsystems/nautilus_trader","slug":"first-submit-fits","errorCode":null,"errorMessage":"first submit fits","messagePattern":"first submit fits","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/event_store/src/writer/mod.rs","lineNumber":1134,"sourceCode":"            Arc::clone(&gate),\n            Arc::clone(&appends_seen),\n        );\n\n        let halt_threshold = Duration::from_millis(50);\n        let config = WriterConfig {\n            channel_capacity: 1,\n            max_batch_entries: 1,\n            max_batch_latency: Duration::from_millis(1),\n            halt_threshold,\n        };\n\n        let clock = get_atomic_clock_static();\n        let boxed = Box::new(backend);\n\n        let writer = EventStoreWriter::spawn(boxed, clock, halt, config).expect(\"spawn\");\n\n        // First submit fits in the channel; the writer thread takes it and blocks.\n        writer.submit(entry_draft(10)).expect(\"first submit fits\");\n\n        // Wait long enough for the writer to dequeue and become blocked at the gate.\n        std::thread::sleep(Duration::from_millis(20));\n\n        // Second and third submits saturate the slot; the channel buffer holds one,\n        // the next one stalls past the halt threshold.\n        let _ = writer.submit(entry_draft(11));\n        let stalled = writer.submit(entry_draft(12)).expect_err(\"must stall\");\n\n        match stalled {\n            SubmitError::HaltSignaled { .. } => {}\n            SubmitError::Closed => panic!(\"expected HaltSignaled, was Closed\"),\n        }\n        let captured_reasons = captured.lock();\n        assert_eq!(\n            captured_reasons.len(),\n            1,\n            \"halt callback must fire exactly once\",","sourceCodeStart":1116,"sourceCodeEnd":1152,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/event_store/src/writer/mod.rs#L1116-L1152","documentation":"EventStoreWriter::submit enqueues an entry draft onto the writer's channel. The expect at writer/mod.rs:1134 ('first submit fits') panics if the first submit returns Err. Since the test uses channel_capacity=1 with a gated backend, the very first submit should fit; failure means the channel was already full, the writer halted, or the writer was closed.","triggerScenarios":"Calling writer.submit(entry_draft(10)) as the first submit when: the channel slot is already occupied, the writer thread has already signaled a halt (latched Closed), or the writer was dropped/closed before this call.","commonSituations":"Tests for backpressure halts where a previous submit already saturated the capacity-1 channel; submit racing with an early halt from a backend failure (GatedDiskFailureBackend); submitting after dropping or closing the writer.","solutions":["Make sure this is genuinely the first submit on a freshly spawned writer","Check captured halt reasons — if a HaltReason is present, the writer latched closed and all submits fail","Do not drop or close the writer before the expected first submit","If a stall is expected later, submit once and wait for the writer thread to dequeue before filling the channel"],"exampleFix":"// before\nwriter.submit(entry_draft(10)).expect(\"first submit fits\");\n// after\nwriter\n    .submit(entry_draft(10))\n    .unwrap_or_else(|e| panic!(\"first submit should fit, got {e:?}\"));","handlingStrategy":"try-catch","validationCode":"let reasons = captured.lock();\nassert!(reasons.is_empty(), \"writer already halted: {:?}\", *reasons);\ndrop(reasons);","typeGuard":"fn writer_accepts_submits(halt_reasons: &[HaltReason]) -> bool {\n    halt_reasons.is_empty()\n}","tryCatchPattern":"match writer.submit(entry_draft(10)) {\n    Ok(()) => {}\n    Err(SubmitError::HaltSignaled { reason, .. }) => eprintln!(\"halted: {reason:?}\"),\n    Err(SubmitError::Closed) => eprintln!(\"writer closed\"),\n}","preventionTips":["Submit the first entry before any backend gate or failure path is exercised","Track halt state via the halt callback before submitting","Never drop or close the writer before planned submits"],"tags":["rust","panic","event-store","backpressure","test-assertion"],"backgroundTag":"invalid-state-transition","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}