C2S client connections not free
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Jabberd |
Incomplete
|
Medium
|
Unassigned |
Bug Description
Problem:
When a client connection closed due to error sent by SM (usually session replaced), the connection is closed but not free. After a while all client mio FD
are not available and C2S reject new connections.
Reason:
The mio_run iterate on active FD and perform accept, connect, read and write action.
In case the FD closed during one of those actions execution, at the end it been free.
The problem occurs when process the FD of the router read action, it receives an error of particular session and find
the associate client connection and close it. Since the router FD is not closed - nobody free this client FD
Fix:
Before start process the FD, keep the value of FD in new mio variable currentFD.
In the mio_close, if the FD that being closed is different from currentFD - free the FD.
Code:
mio_wsasync.h
#define MIO_VARS \
+ int currentFD;
mio_impl.h
function _mio_run
+ MIO(m)->currentFD = fd->fd;
before
/* new conns on a listen socket */
function _mio_close
- if (MIO_CAN_FREE(m))
+ if (MIO_CAN_FREE(m) || MIO(m)->currentFD != fd->fd)
From the look of the proposed change it seems it is a Windows specific hack that affects every other MIO implementation.
We have "int defer_free;" in MIO_VARS that is used to postpone closing the FD to the end of _mio_run.
My guess is that defer_free handling needs fixing in mio_wsasync.h.
Unfortunately I lack Windows programming expertise to properly analyze how wsasync implementation works.