openzoo 0.21.5 → 0.21.6

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/lib/tunnel.js +20 -1
  2. package/package.json +1 -1
package/lib/tunnel.js CHANGED
@@ -20,7 +20,7 @@
20
20
  * OPENZOO_MAX_USD_PER_CALL and/or OPENZOO_TUNNEL_MAX_USD to add them;
21
21
  * - every tunnel-served request is logged with its running spend.
22
22
  */
23
- import { spawn } from 'node:child_process';
23
+ import { spawn, execFileSync } from 'node:child_process';
24
24
  import { createWriteStream } from 'node:fs';
25
25
  import fs from 'node:fs';
26
26
  import path from 'node:path';
@@ -91,8 +91,27 @@ export async function ensureCloudflared(log = console.log) {
91
91
  return cached;
92
92
  }
93
93
 
94
+ /**
95
+ * Kill cloudflared processes left over from previous runs against OUR port.
96
+ *
97
+ * WHY: the proxy exits with its terminal but cloudflared does not always go with
98
+ * it, so repeated `openzoo cursor` runs stack tunnels. Observed: two orphaned
99
+ * cloudflared processes, the editor configured with a third hostname, and every
100
+ * request answering 530/1033 — the editor was pointed at a tunnel whose origin
101
+ * had died while other live tunnels sat there serving nothing.
102
+ */
103
+ function killStaleTunnels(port, log) {
104
+ try {
105
+ const out = execFileSync('pgrep', ['-f', `cloudflared tunnel --url http://localhost:${port}`], { encoding: 'utf8' });
106
+ const pids = out.split('\n').map((x) => x.trim()).filter(Boolean).filter((x) => Number(x) !== process.pid);
107
+ for (const pid of pids) { try { process.kill(Number(pid), 'SIGTERM'); } catch { /* already gone */ } }
108
+ if (pids.length) log(`tunnel: cleared ${pids.length} stale cloudflared process(es) from an earlier run`);
109
+ } catch { /* pgrep exits non-zero when nothing matches — that is the good case */ }
110
+ }
111
+
94
112
  /** Start a quick tunnel to localhost:<port>; resolve with its public URL. */
95
113
  export function startCloudflared(bin, port, log) {
114
+ killStaleTunnels(port, log);
96
115
  return new Promise((resolve, reject) => {
97
116
  // --edge-ip-version 4: cloudflared prefers IPv6+QUIC to reach the edge
98
117
  // whenever the interface merely HAS an IPv6 address — it never checks the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openzoo",
3
- "version": "0.21.5",
3
+ "version": "0.21.6",
4
4
  "description": "Local x402-paying proxy + MCP server for openzoo.fun — point any OpenAI-compatible harness (Cursor, Claude Code, aider, SDKs) at localhost and it pays per call from a local burner wallet. Solana and Base rails live; Robinhood experimental.",
5
5
  "license": "MIT",
6
6
  "type": "module",