vacp2p / nim-libp2p

libp2p implementation in Nim
https://vacp2p.github.io/nim-libp2p/docs/
MIT License
251 stars 55 forks source link

Graceful shutdown process reported as error in logs. #1007

Open cheatfate opened 10 months ago

cheatfate commented 10 months ago

This error statement has been shown on normal shutdown process:

ERR 2024-01-08 18:13:22.437+00:00 Exception in accept loop, exiting topics="libp2p switch" exc="Transport closed, no more connections!"

It happens because of this handler https://github.com/status-im/nim-libp2p/blob/e3c967ad1939fb33b8e13759037d193734acd202/libp2p/switch.nim#L276 which do not knows anything about TransportUseClosedError which can be raised https://github.com/status-im/nim-libp2p/blob/unstable/libp2p/transports/tcptransport.nim#L247-L249 and https://github.com/status-im/nim-libp2p/blob/unstable/libp2p/transports/wstransport.nim#L283-L285

AlejandroCabeza commented 8 months ago

@cheatfate I don't think I follow what you meant. The links you sent don't match with what you mention (I believe). There is a TransportUseClosedError handled (and re-reased) nearby, but none of those links points to it.

One of them points to this piece of code in the same function as the aforementioned except TransportUseClosedError:

  except HttpError as exc:
    debug "Http Error", exc = exc.msg
  except AsyncStreamError as exc:

And the other points to the parameters of the next function, which seems to be unrelated to any TransportUseClosedError:

  hostname: string,
  address: MultiAddress,
  peerId: Opt[PeerId] = Opt.none(PeerId)): Future[Connection] {.async.} =

Do you mean that the "normal shutdown process" somehow triggers the except CatchableError line in the accept proc in switch.nim?

cheatfate commented 8 months ago

Everything what falls into

error "Exception in accept loop, exiting", exc = exc.msg

looks like serious error, and nimbus consumers actually asking what the error is. But this error happens when TransportUseClosedError happens and got catched by this handler. This specific exception MUST not be reported as error type of logs.

diegomrsantos commented 8 months ago

Please, next time it'd be great to have what the expected behavior should be when describing the issue.

diegomrsantos commented 7 months ago

@cheatfate do you have more logs related to it? The error msg "Transport closed, no more connections!" is created by https://github.com/vacp2p/nim-libp2p/blob/c5db35d9b006b597886440293ff5cbd86162452c/libp2p/transports/transport.nim#L38 and can also happen at https://github.com/vacp2p/nim-libp2p/blob/9059a8aced87741de98813bfe0ef2ed63e0217ab/libp2p/transports/tcptransport.nim#L204.

Was there a log "Server was closed" before the one you reported? If it was indeed caused by TransportUseClosedError, there should be one https://github.com/vacp2p/nim-libp2p/blob/9059a8aced87741de98813bfe0ef2ed63e0217ab/libp2p/transports/tcptransport.nim#L234.