fix(network-proxy/websocket): Improve WebSocket connection closure and update router integration
This commit is contained in:
		| @@ -3,6 +3,6 @@ | ||||
|  */ | ||||
| export const commitinfo = { | ||||
|   name: '@push.rocks/smartproxy', | ||||
|   version: '18.1.0', | ||||
|   version: '18.1.1', | ||||
|   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.' | ||||
| } | ||||
|   | ||||
| @@ -500,6 +500,9 @@ export class NetworkProxy implements IMetricsTracker { | ||||
|       this.logger.warn('Router has no recognized configuration method'); | ||||
|     } | ||||
|  | ||||
|     // Update WebSocket handler with new routes | ||||
|     this.webSocketHandler.setRoutes(routes); | ||||
|  | ||||
|     this.logger.info(`Route configuration updated with ${routes.length} routes and ${legacyConfigs.length} proxy configs`); | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -419,9 +419,15 @@ export class WebSocketHandler { | ||||
|         wsIncoming.on('close', (code, reason) => { | ||||
|           this.logger.debug(`WebSocket client connection closed: ${code} ${reason}`); | ||||
|           if (wsOutgoing.readyState === wsOutgoing.OPEN) { | ||||
|             const validCode = code || 1000; | ||||
|             const reasonString = toBuffer(reason).toString(); | ||||
|             wsOutgoing.close(validCode, reasonString); | ||||
|             // Ensure code is a valid WebSocket close code number | ||||
|             const validCode = typeof code === 'number' && code >= 1000 && code <= 4999 ? code : 1000; | ||||
|             try { | ||||
|               const reasonString = reason ? toBuffer(reason).toString() : ''; | ||||
|               wsOutgoing.close(validCode, reasonString); | ||||
|             } catch (err) { | ||||
|               this.logger.error('Error closing wsOutgoing:', err); | ||||
|               wsOutgoing.close(validCode); | ||||
|             } | ||||
|           } | ||||
|  | ||||
|           // Clean up timers | ||||
| @@ -432,9 +438,15 @@ export class WebSocketHandler { | ||||
|         wsOutgoing.on('close', (code, reason) => { | ||||
|           this.logger.debug(`WebSocket target connection closed: ${code} ${reason}`); | ||||
|           if (wsIncoming.readyState === wsIncoming.OPEN) { | ||||
|             const validCode = code || 1000; | ||||
|             const reasonString = toBuffer(reason).toString(); | ||||
|             wsIncoming.close(validCode, reasonString); | ||||
|             // Ensure code is a valid WebSocket close code number | ||||
|             const validCode = typeof code === 'number' && code >= 1000 && code <= 4999 ? code : 1000; | ||||
|             try { | ||||
|               const reasonString = reason ? toBuffer(reason).toString() : ''; | ||||
|               wsIncoming.close(validCode, reasonString); | ||||
|             } catch (err) { | ||||
|               this.logger.error('Error closing wsIncoming:', err); | ||||
|               wsIncoming.close(validCode); | ||||
|             } | ||||
|           } | ||||
|  | ||||
|           // Clean up timers | ||||
|   | ||||
		Reference in New Issue
	
	Block a user