I thought the onexception event was the global exception handler for the server?
It is a server event for uncaught exceptions that terminate client threads on a per-client basis. The event provides the TIdContext belonging to the client thread that is raising the reported exception.
But because of the way they are sending them and the way the Indy FTP server starts at the max passive port for each upload the separate uploads going concurrently must be stepping on each other occasionally, it must be getting a port that is in a timed wait state or something and then when it tries to use it raises that error.
I still don't see how that could cause the error you are seeing. Even if the ENTIRE passive port range were in TIME_WAIT at the time of a new transfer, a bind error during a new transfer should be caught by the invoking command handler (PASV, etc) and not bubble up to the thread that is managing the client connection.
In case the ENTIRE passive port rage is in TAIME_WAIT, I wonder if using the TIdFTPServer.OnDataPortBeforeBind event to enable the ReuseSocket property (ASender.DataChannel.FDataChannel.Socket.ReuseSocket := rsTrue) on each new data transfer socket would help.
I don't know for sure but that seems like what is happening.
I can't answer that without seeing the call stack of the exception on the server side. Can't you please capture that?
I wonder if it would be better to grab a random starting point from the passive port range, or maybe from the max to the mid or something like that instead of doing a down to loop starting at max for each upload and connection.
Adding some element of randomness would probably help. But it still needs to loop through the whole range in the end, and it is more overhead to loop through the entire range using random indexes while avoiding duplicates during the looping. I'll have to figure out an algorithm to do it.
I got this back from the mainframe folks:
150 File status okay; about to open data connection.
EZA2589E Connection to server interrupted or timed out. Waiting for data connect
EZA1636I *** I can't open a data-transfer connection:
426 Data connection closed abnormally.
EZA1735I Std Return Code = 27426, Error Code = 00009
This is the error they saw when the binding error occurred on the server.
That is not very helpful without seeing the exact FTP commands and replies leading up to the error. TIdFTPServer uses 426 for any unexpected error that happens during a data transfer, so there is still a number of things that could be failing to cause that error.