{"record":{"id":"8d84f59781c32441","repo":"clockworklabs/SpacetimeDB","slug":"error-failed-to-read-from-bytessource-d-n","errorCode":null,"errorMessage":"ERROR: Failed to read from BytesSource: %d\\n","messagePattern":"ERROR: Failed to read from BytesSource: (.+?)\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/bindings-cpp/src/internal/Module.cpp","lineNumber":417,"sourceCode":"    auto ret = FFI::bytes_source_remaining_length(source, &remaining_len);\n    if (ret != 0) {\n        // If we can't get the length, fall back to incremental reading\n        // This shouldn't happen with current host implementation\n        constexpr size_t CHUNK_SIZE = 1024;\n        iter_buf.reserve(CHUNK_SIZE);\n        \n        while (true) {\n            size_t chunk_size = CHUNK_SIZE;\n            size_t old_size = iter_buf.size();\n            iter_buf.resize(old_size + chunk_size);\n            \n            ret = FFI::bytes_source_read(source, iter_buf.data() + old_size, &chunk_size);\n            iter_buf.resize(old_size + chunk_size);  // Resize to actual bytes read\n            \n            if (ret == -1) {  // EXHAUSTED\n                break;\n            } else if (ret != 0) {  // Error\n                fprintf(stderr, \"ERROR: Failed to read from BytesSource: %d\\n\", ret);\n                break;\n            }\n        }\n        return iter_buf.release();\n    }\n    \n    // Reserve exact size needed (often no-op since pool buffer is 64 KiB)\n    iter_buf.resize(remaining_len);  // Resize to exact size BEFORE reading\n    \n    // Read all bytes - should complete in one call since we have capacity\n    size_t bytes_read = 0;\n    while (bytes_read < remaining_len) {\n        size_t chunk_size = remaining_len - bytes_read;\n        ret = FFI::bytes_source_read(source, iter_buf.data() + bytes_read, &chunk_size);\n        bytes_read += chunk_size;\n        \n        if (ret == -1) {  // EXHAUSTED\n            break;","sourceCodeStart":399,"sourceCodeEnd":435,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/bindings-cpp/src/internal/Module.cpp#L399-L435","documentation":"Runtime FFI error inside ConsumeBytes' unknown-length read loop: FFI::bytes_source_read returned a status other than 0 (OK) or -1 (EXHAUSTED) while draining the BytesSource that carries reducer/HTTP arguments across the Wasm boundary. The message is logged and the loop breaks, so the caller receives a truncated buffer and the failure usually resurfaces as a BSATN deserialization error downstream.","triggerScenarios":"The host-side byte stream faults mid-read while the module drains reducer arguments of unknown length; ABI/host version mismatch between the module binary and the spacetimedb host; corrupted or closed BytesSource passed across the FFI boundary.","commonSituations":"Publishing a module built with an older bindings-cpp ABI against a newer server (or vice versa); intermittent host I/O failures; truncation of large argument payloads at the Wasm boundary.","solutions":["Rebuild and republish the module with the same spacetimedb toolchain/CLI version used by the server so the FFI ABI matches","Check the server/host logs for the underlying read failure at the same timestamp - the module-side message only mirrors it","If it reproduces with a specific large argument, reduce the payload or split the call to rule out size-related truncation","If persistent, report with the returned status code (the %d value) to SpacetimeDB maintainers - nonzero non-minus-one statuses are host-side faults"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build and publish the module with the same spacetimedb CLI version as the server","Treat this as an infrastructure fault: check host/server logs at the same timestamp","Make reducers tolerant of argument deserialization failure (validate inputs, return clean errors) so a truncated stream surfaces as a user-visible error, not a crash"],"tags":["spacetimedb","cpp","ffi","wasm","serialization","runtime"],"backgroundTag":"bytes-source-read-failed","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}