@push.rocks/smartproxy 19.5.4 → 19.5.5
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.
- package/dist_ts/core/utils/async-utils.d.ts +81 -0
- package/dist_ts/core/utils/async-utils.js +216 -0
- package/dist_ts/core/utils/binary-heap.d.ts +73 -0
- package/dist_ts/core/utils/binary-heap.js +193 -0
- package/dist_ts/core/utils/enhanced-connection-pool.d.ts +110 -0
- package/dist_ts/core/utils/enhanced-connection-pool.js +320 -0
- package/dist_ts/core/utils/fs-utils.d.ts +144 -0
- package/dist_ts/core/utils/fs-utils.js +252 -0
- package/dist_ts/core/utils/index.d.ts +5 -2
- package/dist_ts/core/utils/index.js +6 -3
- package/dist_ts/core/utils/lifecycle-component.d.ts +59 -0
- package/dist_ts/core/utils/lifecycle-component.js +195 -0
- package/dist_ts/plugins.d.ts +2 -1
- package/dist_ts/plugins.js +3 -2
- package/dist_ts/proxies/http-proxy/certificate-manager.d.ts +15 -0
- package/dist_ts/proxies/http-proxy/certificate-manager.js +49 -2
- package/dist_ts/proxies/nftables-proxy/nftables-proxy.d.ts +10 -0
- package/dist_ts/proxies/nftables-proxy/nftables-proxy.js +53 -43
- package/dist_ts/proxies/smart-proxy/cert-store.js +22 -20
- package/dist_ts/proxies/smart-proxy/connection-manager.d.ts +37 -7
- package/dist_ts/proxies/smart-proxy/connection-manager.js +257 -180
- package/package.json +2 -2
- package/readme.hints.md +96 -1
- package/readme.plan.md +1135 -221
- package/readme.problems.md +167 -83
- package/ts/core/utils/async-utils.ts +275 -0
- package/ts/core/utils/binary-heap.ts +225 -0
- package/ts/core/utils/enhanced-connection-pool.ts +420 -0
- package/ts/core/utils/fs-utils.ts +270 -0
- package/ts/core/utils/index.ts +5 -2
- package/ts/core/utils/lifecycle-component.ts +231 -0
- package/ts/plugins.ts +2 -1
- package/ts/proxies/http-proxy/certificate-manager.ts +52 -1
- package/ts/proxies/nftables-proxy/nftables-proxy.ts +64 -79
- package/ts/proxies/smart-proxy/cert-store.ts +26 -20
- package/ts/proxies/smart-proxy/connection-manager.ts +291 -189
- package/readme.plan2.md +0 -764
- package/ts/common/eventUtils.ts +0 -34
- package/ts/common/types.ts +0 -91
- package/ts/core/utils/event-system.ts +0 -376
- package/ts/core/utils/event-utils.ts +0 -25
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@push.rocks/smartproxy",
|
|
3
|
-
"version": "19.5.
|
|
3
|
+
"version": "19.5.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A powerful proxy package with unified route-based configuration for high traffic management. Features include SSL/TLS support, flexible routing patterns, WebSocket handling, advanced security options, and automatic ACME certificate management.",
|
|
6
6
|
"main": "dist_ts/index.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"@git.zone/tsbuild": "^2.6.4",
|
|
13
13
|
"@git.zone/tsrun": "^1.2.44",
|
|
14
14
|
"@git.zone/tstest": "^2.3.1",
|
|
15
|
-
"@types/node": "^22.15.
|
|
15
|
+
"@types/node": "^22.15.29",
|
|
16
16
|
"typescript": "^5.8.3"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
package/readme.hints.md
CHANGED
|
@@ -318,4 +318,99 @@ const routes: IRouteConfig[] = [{
|
|
|
318
318
|
- Authentication requires TLS termination (cannot be enforced on passthrough/direct connections)
|
|
319
319
|
- Per-route connection limits are not yet implemented
|
|
320
320
|
- Security is defined at the route level (route.security), not in the action
|
|
321
|
-
- Route matching is based solely on match criteria; security is enforced after matching
|
|
321
|
+
- Route matching is based solely on match criteria; security is enforced after matching
|
|
322
|
+
|
|
323
|
+
## Performance Issues Investigation (v19.5.3+)
|
|
324
|
+
|
|
325
|
+
### Critical Blocking Operations Found
|
|
326
|
+
1. **Busy Wait Loop** in `ts/proxies/nftables-proxy/nftables-proxy.ts:235-238`
|
|
327
|
+
- Blocks entire event loop with `while (Date.now() < waitUntil) {}`
|
|
328
|
+
- Should use `await new Promise(resolve => setTimeout(resolve, delay))`
|
|
329
|
+
|
|
330
|
+
2. **Synchronous Filesystem Operations**
|
|
331
|
+
- Certificate management uses `fs.existsSync()`, `fs.mkdirSync()`, `fs.readFileSync()`
|
|
332
|
+
- NFTables proxy uses `execSync()` for system commands
|
|
333
|
+
- Certificate store uses `ensureDirSync()`, `fileExistsSync()`, `removeManySync()`
|
|
334
|
+
|
|
335
|
+
3. **Memory Leak Risks**
|
|
336
|
+
- Several `setInterval()` calls without storing references for cleanup
|
|
337
|
+
- Event listeners added without proper cleanup in error paths
|
|
338
|
+
- Missing `removeAllListeners()` calls in some connection cleanup scenarios
|
|
339
|
+
|
|
340
|
+
### Performance Recommendations
|
|
341
|
+
- Replace all sync filesystem operations with async alternatives
|
|
342
|
+
- Fix the busy wait loop immediately (critical event loop blocker)
|
|
343
|
+
- Add proper cleanup for all timers and event listeners
|
|
344
|
+
- Consider worker threads for CPU-intensive operations
|
|
345
|
+
- See `readme.problems.md` for detailed analysis and recommendations
|
|
346
|
+
|
|
347
|
+
## Performance Optimizations Implemented (Phase 1 - v19.6.0)
|
|
348
|
+
|
|
349
|
+
### 1. Async Utilities Created (`ts/core/utils/async-utils.ts`)
|
|
350
|
+
- **delay()**: Non-blocking alternative to busy wait loops
|
|
351
|
+
- **retryWithBackoff()**: Retry operations with exponential backoff
|
|
352
|
+
- **withTimeout()**: Execute operations with timeout protection
|
|
353
|
+
- **parallelLimit()**: Run async operations with concurrency control
|
|
354
|
+
- **debounceAsync()**: Debounce async functions
|
|
355
|
+
- **AsyncMutex**: Ensure exclusive access to resources
|
|
356
|
+
- **CircuitBreaker**: Protect against cascading failures
|
|
357
|
+
|
|
358
|
+
### 2. Filesystem Utilities Created (`ts/core/utils/fs-utils.ts`)
|
|
359
|
+
- **AsyncFileSystem**: Complete async filesystem operations
|
|
360
|
+
- exists(), ensureDir(), readFile(), writeFile()
|
|
361
|
+
- readJSON(), writeJSON() with proper error handling
|
|
362
|
+
- copyFile(), moveFile(), removeDir()
|
|
363
|
+
- Stream creation and file listing utilities
|
|
364
|
+
|
|
365
|
+
### 3. Critical Fixes Applied
|
|
366
|
+
|
|
367
|
+
#### Busy Wait Loop Fixed
|
|
368
|
+
- **Location**: `ts/proxies/nftables-proxy/nftables-proxy.ts:235-238`
|
|
369
|
+
- **Fix**: Replaced `while (Date.now() < waitUntil) {}` with `await delay(ms)`
|
|
370
|
+
- **Impact**: Unblocks event loop, massive performance improvement
|
|
371
|
+
|
|
372
|
+
#### Certificate Manager Migration
|
|
373
|
+
- **File**: `ts/proxies/http-proxy/certificate-manager.ts`
|
|
374
|
+
- Added async initialization method
|
|
375
|
+
- Kept sync methods for backward compatibility with deprecation warnings
|
|
376
|
+
- Added `loadDefaultCertificatesAsync()` method
|
|
377
|
+
|
|
378
|
+
#### Certificate Store Migration
|
|
379
|
+
- **File**: `ts/proxies/smart-proxy/cert-store.ts`
|
|
380
|
+
- Replaced all `fileExistsSync`, `ensureDirSync`, `removeManySync`
|
|
381
|
+
- Used parallel operations with `Promise.all()` for better performance
|
|
382
|
+
- Improved error handling and async JSON operations
|
|
383
|
+
|
|
384
|
+
#### NFTables Proxy Improvements
|
|
385
|
+
- Added deprecation warnings to sync methods
|
|
386
|
+
- Created `executeWithTempFile()` helper for common pattern
|
|
387
|
+
- Started migration of sync filesystem operations to async
|
|
388
|
+
- Added import for delay and AsyncFileSystem utilities
|
|
389
|
+
|
|
390
|
+
### 4. Backward Compatibility Maintained
|
|
391
|
+
- All sync methods retained with deprecation warnings
|
|
392
|
+
- Existing APIs unchanged, new async methods added alongside
|
|
393
|
+
- Feature flags prepared for gradual rollout
|
|
394
|
+
|
|
395
|
+
### 5. Phase 1 Completion Status
|
|
396
|
+
✅ **Phase 1 COMPLETE** - All critical performance fixes have been implemented:
|
|
397
|
+
- ✅ Fixed busy wait loop in nftables-proxy.ts
|
|
398
|
+
- ✅ Created async utilities (delay, retry, timeout, parallelLimit, mutex, circuit breaker)
|
|
399
|
+
- ✅ Created filesystem utilities (AsyncFileSystem with full async operations)
|
|
400
|
+
- ✅ Migrated all certificate management to async operations
|
|
401
|
+
- ✅ Migrated nftables-proxy filesystem operations to async (except stopSync for exit handlers)
|
|
402
|
+
- ✅ All tests passing for new utilities
|
|
403
|
+
|
|
404
|
+
### 6. Phase 2 Progress Status
|
|
405
|
+
🔨 **Phase 2 IN PROGRESS** - Resource Lifecycle Management:
|
|
406
|
+
- ✅ Created LifecycleComponent base class for automatic resource cleanup
|
|
407
|
+
- ✅ Created BinaryHeap data structure for priority queue operations
|
|
408
|
+
- ✅ Created EnhancedConnectionPool with backpressure and health checks
|
|
409
|
+
- ✅ Cleaned up legacy code (removed ts/common/, event-utils.ts, event-system.ts)
|
|
410
|
+
- 📋 TODO: Migrate existing components to extend LifecycleComponent
|
|
411
|
+
- 📋 TODO: Add integration tests for resource management
|
|
412
|
+
|
|
413
|
+
### 7. Next Steps (Remaining Work)
|
|
414
|
+
- **Phase 2 (cont)**: Migrate components to use LifecycleComponent
|
|
415
|
+
- **Phase 3**: Add worker threads for CPU-intensive operations
|
|
416
|
+
- **Phase 4**: Performance monitoring dashboard
|