@push.rocks/smartproxy 19.6.2 → 19.6.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.
@@ -1,202 +0,0 @@
1
- # Production Connection Monitoring
2
-
3
- This document explains how to use the ProductionConnectionMonitor to diagnose connection accumulation issues in real-time.
4
-
5
- ## Quick Start
6
-
7
- ```typescript
8
- import ProductionConnectionMonitor from './.nogit/debug/production-connection-monitor.js';
9
-
10
- // After starting your proxy
11
- const monitor = new ProductionConnectionMonitor(proxy);
12
- monitor.start(5000); // Check every 5 seconds
13
-
14
- // The monitor will automatically capture diagnostics when:
15
- // - Connections exceed 50 (default threshold)
16
- // - Sudden spike of 20+ connections occurs
17
- // - You manually call monitor.forceCaptureNow()
18
- ```
19
-
20
- ## What Gets Captured
21
-
22
- When accumulation is detected, the monitor saves a JSON file with:
23
-
24
- ### Connection Details
25
- - Socket states (destroyed, readable, writable, readyState)
26
- - Connection age and activity timestamps
27
- - Data transfer statistics (bytes sent/received)
28
- - Target host and port information
29
- - Keep-alive status
30
- - Event listener counts
31
-
32
- ### System State
33
- - Memory usage
34
- - Event loop lag
35
- - Connection count trends
36
- - Termination statistics
37
-
38
- ## Reading Diagnostic Files
39
-
40
- Files are saved to `.nogit/connection-diagnostics/` with names like:
41
- ```
42
- accumulation_2025-06-07T20-20-43-733Z_force_capture.json
43
- ```
44
-
45
- ### Key Fields to Check
46
-
47
- 1. **Socket States**
48
- ```json
49
- "incomingState": {
50
- "destroyed": false,
51
- "readable": true,
52
- "writable": true,
53
- "readyState": "open"
54
- }
55
- ```
56
- - Both destroyed = zombie connection
57
- - One destroyed = half-zombie
58
- - Both alive but old = potential stuck connection
59
-
60
- 2. **Data Transfer**
61
- ```json
62
- "bytesReceived": 36,
63
- "bytesSent": 0,
64
- "timeSinceLastActivity": 60000
65
- ```
66
- - No bytes sent back = stuck connection
67
- - High bytes but old = slow backend
68
- - No activity = idle connection
69
-
70
- 3. **Connection Flags**
71
- ```json
72
- "hasReceivedInitialData": false,
73
- "hasKeepAlive": true,
74
- "connectionClosed": false
75
- ```
76
- - hasReceivedInitialData=false on non-TLS = immediate routing
77
- - hasKeepAlive=true = extended timeout applies
78
- - connectionClosed=false = still tracked
79
-
80
- ## Common Patterns
81
-
82
- ### 1. Hanging Backend Pattern
83
- ```json
84
- {
85
- "bytesReceived": 36,
86
- "bytesSent": 0,
87
- "age": 120000,
88
- "targetHost": "backend.example.com",
89
- "incomingState": { "destroyed": false },
90
- "outgoingState": { "destroyed": false }
91
- }
92
- ```
93
- **Fix**: The stuck connection detection (60s timeout) should clean these up.
94
-
95
- ### 2. Zombie Connection Pattern
96
- ```json
97
- {
98
- "incomingState": { "destroyed": true },
99
- "outgoingState": { "destroyed": true },
100
- "connectionClosed": false
101
- }
102
- ```
103
- **Fix**: The zombie detection should clean these up within 30s.
104
-
105
- ### 3. Event Listener Leak Pattern
106
- ```json
107
- {
108
- "incomingListeners": {
109
- "data": 15,
110
- "error": 20,
111
- "close": 18
112
- }
113
- }
114
- ```
115
- **Issue**: Event listeners accumulating, potential memory leak.
116
-
117
- ### 4. No Outgoing Socket Pattern
118
- ```json
119
- {
120
- "outgoingState": { "exists": false },
121
- "connectionClosed": false,
122
- "age": 5000
123
- }
124
- ```
125
- **Issue**: Connection setup failed but cleanup didn't trigger.
126
-
127
- ## Forcing Diagnostic Capture
128
-
129
- To capture current state immediately:
130
- ```typescript
131
- monitor.forceCaptureNow();
132
- ```
133
-
134
- This is useful when you notice accumulation starting.
135
-
136
- ## Automated Analysis
137
-
138
- The monitor automatically analyzes patterns and logs:
139
- - Zombie/half-zombie counts
140
- - Stuck connection counts
141
- - Old connection counts
142
- - Memory usage
143
- - Recommendations
144
-
145
- ## Integration Example
146
-
147
- ```typescript
148
- // In your proxy startup script
149
- import { SmartProxy } from '@push.rocks/smartproxy';
150
- import ProductionConnectionMonitor from './production-connection-monitor.js';
151
-
152
- async function startProxyWithMonitoring() {
153
- const proxy = new SmartProxy({
154
- // your config
155
- });
156
-
157
- await proxy.start();
158
-
159
- // Start monitoring
160
- const monitor = new ProductionConnectionMonitor(proxy);
161
- monitor.start(5000);
162
-
163
- // Optional: Capture on specific events
164
- process.on('SIGUSR1', () => {
165
- console.log('Manual diagnostic capture triggered');
166
- monitor.forceCaptureNow();
167
- });
168
-
169
- // Graceful shutdown
170
- process.on('SIGTERM', async () => {
171
- monitor.stop();
172
- await proxy.stop();
173
- process.exit(0);
174
- });
175
- }
176
- ```
177
-
178
- ## Troubleshooting
179
-
180
- ### Monitor Not Detecting Accumulation
181
- - Check threshold settings (default: 50 connections)
182
- - Reduce check interval for faster detection
183
- - Use forceCaptureNow() to capture current state
184
-
185
- ### Too Many False Positives
186
- - Increase accumulation threshold
187
- - Increase spike threshold
188
- - Adjust check interval
189
-
190
- ### Missing Diagnostic Data
191
- - Ensure output directory exists and is writable
192
- - Check disk space
193
- - Verify process has write permissions
194
-
195
- ## Next Steps
196
-
197
- 1. Deploy the monitor to production
198
- 2. Wait for accumulation to occur
199
- 3. Share diagnostic files for analysis
200
- 4. Apply targeted fixes based on patterns found
201
-
202
- The diagnostic data will reveal the exact state of connections when accumulation occurs, enabling precise fixes for your specific scenario.