Web Server Socket Timeout Handling for Abnormal Client Connections
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
MAC notebooks from Apple experience issues with continuous browsing or operation on Web servers due to the Web task being unable to receive semaphores from the Socket underlying layer, resulting in a waiting state and inability to process procedures like connecting, reading, or writing, as the Socket underlying layer does not monitor or obtain client Socket events.
Innovation Solution
A method and apparatus for processing Sockets in a Web server based on an asynchronous unblocking-mode Socket, which involves monitoring client requests, registering Socket events, judging whether the events are READ or WRITE events, starting a timer, and sending a second semaphore when the preset threshold is reached to activate the Web task and process corresponding procedures, including closing the Socket event if necessary.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Productivity
If asynchronous unblocking-mode Socket is used in embedded Rex system, then communication efficiency is improved, but the Web task cannot receive semaphores when client is abnormal, causing the system to freeze
Solution Approach 1:
The patent applies preliminary action by setting a timeout mechanism in advance. The Web server monitors Socket events with a predetermined timeout threshold, and when the threshold is exceeded without receiving client requests, the server proactively closes the Socket connection. This prevents the Web task from freezing indefinitely while maintaining the efficiency of asynchronous Socket communication.
2Productivity
If the Socket underlying layer does not monitor client events, then the asynchronous Socket mechanism works efficiently, but the Web task enters an infinite waiting state
Solution Approach 1:
The patent implements feedback by having the Web server continuously monitor Socket events and compare the current time with the connection establishment time. When the time difference exceeds the timeout threshold, the server receives feedback that the client is abnormal and takes corrective action by closing the connection. This feedback mechanism prevents infinite waiting while preserving asynchronous processing efficiency.
3Adaptability or versatility
If the Web server waits for client requests indefinitely, then all client operations are handled, but the server becomes unresponsive to new connections
Solution Approach 1:
The patent applies dynamics by making the Socket connection state adaptive. The server dynamically monitors each Socket connection and automatically transitions from an open state to a closed state when the client becomes abnormal (detected via timeout). This dynamic state management ensures the server remains responsive to new connections while still handling operations from active clients.
Data Source
Figure 1
Figure 2
Figure 3
AI summary
A method for processing a Socket and apparatus and a Web server are provided. The method for processing a Socket is applied in a Web server. The Web server is based on a platform for providing an asynchronous unblocking-mode Socket. The method includes: monitoring a client request of a port of the Web server; according to the monitored client request, registering a Socket event through an asynchronous selection operation; judging whether the Socket event is a READ event and/or a WRITE event, to obtain a judgment result; when the judgment result indicates that the Socket event is a READ event and/or a WRITE event, starting timing; and when the timing reaches a preset threshold and the Web task does not receive a first semaphore sent by a Socket underlying layer, sending a second semaphore to the Web task, so that the Web task can be activated, and a corresponding procedure is processed according to the Socket event. In the embodiments of the present invention, when an exception occurs at a client, a Web server can still be accessed.