@torrent-tv/proxy 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/cli.js +26 -1
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -136,6 +136,31 @@ async function registerClientSafe() {
136
136
  }
137
137
  }
138
138
 
139
+ /**
140
+ * Register this proxy with the registry server, retrying indefinitely
141
+ * with exponential backoff until it succeeds. This allows the proxy to
142
+ * survive temporary server outages (restarts, deployments) without crashing.
143
+ *
144
+ * @returns {Promise<void>}
145
+ */
146
+ async function registerWithRetry() {
147
+ const MAX_DELAY_MS = 60_000;
148
+ let delayMs = 2_000;
149
+ let attempt = 0;
150
+ while (true) {
151
+ attempt++;
152
+ try {
153
+ await registerClientSafe();
154
+ return;
155
+ } catch (error) {
156
+ const message = error instanceof Error ? error.message : String(error);
157
+ logger.warn(`Registration attempt ${attempt} failed: ${message}. Retrying in ${delayMs / 1000}s…`);
158
+ await new Promise((resolve) => setTimeout(resolve, delayMs));
159
+ delayMs = Math.min(delayMs * 2, MAX_DELAY_MS);
160
+ }
161
+ }
162
+ }
163
+
139
164
  /**
140
165
  * Gracefully shut down the tunnel, heartbeat timer, and HTTP server.
141
166
  *
@@ -188,7 +213,7 @@ try {
188
213
  logger.info(`Optional HLS audio transcode is enabled (ffmpeg: ${ffmpegBin}).`);
189
214
  }
190
215
 
191
- await registerClientSafe();
216
+ await registerWithRetry();
192
217
 
193
218
  tunnelClient = createTunnelClient({
194
219
  serverUrl,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@torrent-tv/proxy",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Torrent proxy client that exposes webseed-like HTTP stream endpoint.",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "publishConfig": {