runtime icon indicating copy to clipboard operation
runtime copied to clipboard

How to tell if a connect timeout is caused by caller or callee?

Open fstugren opened this issue 3 years ago • 4 comments

Hi team

This connectivity issue is related to a couple of issues I opened in the past https://github.com/dotnet/runtime/issues/78070 and https://github.com/dotnet/runtime/issues/63706.

My team runs a large number of services, most of which are running Asp.Net 6.0 on top of AKS/Linux. Services call each other a lot. Occasionally we see connectivity timeouts. This makes the calling service fail with a TimeoutException ("A connection could not be established within the configured ConnectTimeout."). The caller uses this exception to identify this as a connectivity error, vs. a situation where the timeout is caused by the server taking too long to process the request. Errors like this can't be correlated with anything on the callee side, because requests fail too early, in the connection stage, so the callee has no logs.

The philosophical problem with those errors is that while they can be detected at the caller side, the exception in the .Net layer does not provide any information whether:

  • The call failed because there was a problem on the caller's side (outbound port exhaustion?)
  • The call failed because there was a problem on the callee's side (inbound port exhaustion? Server too busy?)

This lack of certainty often leads to bugs and incidents being passed from one team to the other:

  • Caller service team says "calls to other services at the same time work fine, just calls to this service fail to connect."
  • Callee service team says "there doesn't seem to be a problem on our side, we see none or very few failed requests."

Is there anything the runtime team can recommend on how to use the HttpClient or SocketsHttpHandler to get more information about connectivity errors?

This could be investigated by logging on the physical machines and running network stack commands like netstat to look at ports and connections, but the problem is that by the time someone logs on the problem is mitigated.

Is there anything we could do to make our life easier? Any tools that can be configured in production to help identify the cause? Any other ideas?

Thanks F. [I tagged several people who answered my prior questions: @stephentoub, @ManickaP, @karelz, @wfurt, @MihaZupan]

fstugren avatar Mar 27 '23 20:03 fstugren

Tagging subscribers to this area: @dotnet/ncl See info in area-owners.md if you want to be subscribed.

Issue Details

Hi team

This connectivity issue is related to a couple of issues I opened in the past https://github.com/dotnet/runtime/issues/78070 and https://github.com/dotnet/runtime/issues/63706.

My team runs a large number of services, most of which are running Asp.Net 6.0 on top of AKS/Linux. Services call each other a lot. Occasionally we see connectivity timeouts. This makes the calling service fail with a TimeoutException ("A connection could not be established within the configured ConnectTimeout."). The caller uses this exception to identify this as a connectivity error, vs. a situation where the timeout is caused by the server taking too long to process the request. Errors like this can't be correlated with anything on the callee side, because requests fail too early, in the connection stage, so the callee has no logs.

The philosophical problem with those errors is that while they can be detected at the caller side, the exception in the .Net layer does not provide any information whether:

  • The call failed because there was a problem on the caller's side (outbound port exhaustion?)
  • The call failed because there was a problem on the callee's side (inbound port exhaustion? Server too busy?)

This lack of certainty often leads to bugs and incidents being passed from one team to the other:

  • Caller service team says "calls to other services at the same time work fine, just calls to this service fail to connect."
  • Callee service team says "there doesn't seem to be a problem on our side, we see none or very few failed requests."

Is there anything the runtime team can recommend on how to use the HttpClient or SocketsHttpHandler to get more information about connectivity errors?

This could be investigated by logging on the physical machines and running network stack commands like netstat to look at ports and connections, but the problem is that by the time someone logs on the problem is mitigated.

Is there anything we could do to make our life easier? Any tools that can be configured in production to help identify the cause? Any other ideas?

Thanks F. [I tagged several people who answered my prior questions: @stephentoub, @ManickaP, @karelz, @wfurt, @MihaZupan]

Author: fstugren
Assignees: -
Labels:

area-System.Net, untriaged, needs-area-label

Milestone: -

ghost avatar Mar 27 '23 21:03 ghost

Tagging subscribers to this area: @dotnet/ncl See info in area-owners.md if you want to be subscribed.

Issue Details

Hi team

This connectivity issue is related to a couple of issues I opened in the past https://github.com/dotnet/runtime/issues/78070 and https://github.com/dotnet/runtime/issues/63706.

My team runs a large number of services, most of which are running Asp.Net 6.0 on top of AKS/Linux. Services call each other a lot. Occasionally we see connectivity timeouts. This makes the calling service fail with a TimeoutException ("A connection could not be established within the configured ConnectTimeout."). The caller uses this exception to identify this as a connectivity error, vs. a situation where the timeout is caused by the server taking too long to process the request. Errors like this can't be correlated with anything on the callee side, because requests fail too early, in the connection stage, so the callee has no logs.

The philosophical problem with those errors is that while they can be detected at the caller side, the exception in the .Net layer does not provide any information whether:

  • The call failed because there was a problem on the caller's side (outbound port exhaustion?)
  • The call failed because there was a problem on the callee's side (inbound port exhaustion? Server too busy?)

This lack of certainty often leads to bugs and incidents being passed from one team to the other:

  • Caller service team says "calls to other services at the same time work fine, just calls to this service fail to connect."
  • Callee service team says "there doesn't seem to be a problem on our side, we see none or very few failed requests."

Is there anything the runtime team can recommend on how to use the HttpClient or SocketsHttpHandler to get more information about connectivity errors?

This could be investigated by logging on the physical machines and running network stack commands like netstat to look at ports and connections, but the problem is that by the time someone logs on the problem is mitigated.

Is there anything we could do to make our life easier? Any tools that can be configured in production to help identify the cause? Any other ideas?

Thanks F. [I tagged several people who answered my prior questions: @stephentoub, @ManickaP, @karelz, @wfurt, @MihaZupan]

Author: fstugren
Assignees: -
Labels:

area-System.Net.Http, untriaged

Milestone: -

ghost avatar Mar 28 '23 01:03 ghost

I don't think you can determine the side in most cases. Imagine the simple case: Http calls Socket.Connect and that call Kernel. That would send out SYN. It does not matter if the outgoing SYN is lost or if the server does not respond. The call will fail and .NET will return error code from the Kernel. I don't think we (or Kernel) would ever know.

There are cases when peer or something along the way actively refuses the connection - either via ICMP or TCP RST. That would be sign that the attempt was made. But if you look at cases like #82820 even if you see some response it may or may not came from the actual server. Security services meddling with base networking are more and more common.

If you have troubles with outbound, perhaps one way to approach it would be adding probes to well-know stable servers.

wfurt avatar Mar 28 '23 18:03 wfurt

Triage: closing as answered above. Feel free to reopen if more information is needed.

CarnaViire avatar Apr 06 '23 20:04 CarnaViire