-
Notifications
You must be signed in to change notification settings - Fork 349
Description
Connection timeout is implemented by disposing a TcpClient; after this happens, the ObjectDisposedException is preserved as the InnerException for a MySqlException:
| throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "Connect Timeout expired.", ex); |
This was done to provide additional diagnostic information.
Despite the clear outer exception message, this routinely gets reported as an ObjectDisposedException, e.g.,:
- Disposed socket on connect timeout #871
- System.ObjectDisposedException #881
- ObjectDisposedException: Cannot access a disposed object. Object name: 'System.Net.Sockets.Socket'. #548
- Cannot access a disposed object(Socket) leads to a Timeout expired MySqlException #1020
This may be exacerbated by monitoring tools reporting the inner exception. (This screenshot from Application Insights is a slightly different inner exception but I think I've seen the same problem with it.)
The ObjectDisposedException is really just a detail of how timeout is currently implemented and ultimately not germane to the connection timeout; to avoid potential confusion we should throw a MySqlException with no inner exception. (This is potentially a breaking change if anyone had a catch () when block based on the inner exception.)
