Skip to content

Commit 281d04b

Browse files
authored
Merge pull request #67 from helius-labs/dont-yield
Fix: Only report reconnection errors after exhausting all retries
2 parents d69d758 + b26ee7d commit 281d04b

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

javascript/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

javascript/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "laserstream-napi"
3-
version = "0.2.5"
3+
version = "0.2.6"
44
edition = "2021"
55

66
[lib]

javascript/napi-src/stream.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const FORK_DEPTH_SAFETY_MARGIN: u64 = 31; // Max fork depth for processed commit
2222

2323
// SDK metadata constants
2424
const SDK_NAME: &str = "laserstream-javascript";
25-
const SDK_VERSION: &str = "0.2.4";
25+
const SDK_VERSION: &str = "0.2.6";
2626

2727
/// Custom interceptor that adds SDK metadata headers to all gRPC requests
2828
#[derive(Clone)]
@@ -156,23 +156,22 @@ impl StreamInner {
156156
reconnect_attempts = 1; // Reset to 1 since this is the first attempt after progress
157157
}
158158

159-
// Report every error as it happens
160-
let error_msg = format!("Connection error (attempt {}): {}", reconnect_attempts, e);
161-
let _ = ts_callback.call(Err(napi::Error::from_reason(error_msg)), ThreadsafeFunctionCallMode::Blocking);
159+
// Log error internally but don't yield to consumer until max attempts exhausted
160+
eprintln!("RECONNECT: Connection failed (attempt {}/{}): {}", reconnect_attempts, effective_max_attempts, e);
162161

163162
// Check if exceeded max reconnect attempts
163+
if reconnect_attempts >= effective_max_attempts {
164+
// Only report error to consumer after exhausting all retries
165+
let error_msg = format!("Connection failed after {} attempts: {}", effective_max_attempts, e);
166+
let _ = ts_callback.call(Err(napi::Error::from_reason(error_msg)), ThreadsafeFunctionCallMode::Blocking);
167+
break;
168+
}
164169
}
165170
}
166171

167-
if reconnect_attempts >= effective_max_attempts {
168-
// Exceeded max reconnect attempts - call error callback one final time
169-
let error_msg = format!("Connection failed after {} attempts", effective_max_attempts);
170-
let _ = ts_callback.call(Err(napi::Error::from_reason(error_msg)), ThreadsafeFunctionCallMode::Blocking);
171-
break;
172-
}
173-
174172
// Determine where to resume based on commitment level.
175173
let last_tracked_slot = tracked_slot.load(Ordering::SeqCst);
174+
eprintln!("RECONNECT: tracked_slot={}", last_tracked_slot);
176175

177176
// Only use from_slot when replay is enabled
178177
if last_tracked_slot > 0 && replay {

javascript/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "helius-laserstream",
3-
"version": "0.2.5",
3+
"version": "0.2.6",
44
"description": "High-performance Laserstream gRPC client with automatic reconnection",
55
"main": "client.js",
66
"types": "client.d.ts",
@@ -83,12 +83,12 @@
8383
}
8484
},
8585
"optionalDependencies": {
86-
"helius-laserstream-darwin-arm64": "0.2.5",
87-
"helius-laserstream-darwin-x64": "0.2.5",
88-
"helius-laserstream-linux-arm64-gnu": "0.2.5",
89-
"helius-laserstream-linux-arm64-musl": "0.2.5",
90-
"helius-laserstream-linux-x64-gnu": "0.2.5",
91-
"helius-laserstream-linux-x64-musl": "0.2.5"
86+
"helius-laserstream-darwin-arm64": "0.2.6",
87+
"helius-laserstream-darwin-x64": "0.2.6",
88+
"helius-laserstream-linux-arm64-gnu": "0.2.6",
89+
"helius-laserstream-linux-arm64-musl": "0.2.6",
90+
"helius-laserstream-linux-x64-gnu": "0.2.6",
91+
"helius-laserstream-linux-x64-musl": "0.2.6"
9292
},
9393
"dependencies": {
9494
"@types/protobufjs": "^6.0.0",

0 commit comments

Comments
 (0)