Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid pointless exception raising in dcutr/server #1063

Merged
merged 2 commits into from
Mar 12, 2024

Conversation

etan-status
Copy link
Contributor

dcutr/server is the only protocol handler outside tests / examples that raises exceptions. The only caller of this handler is defined in MultStreamSelect.handle, which has a surrounding except block that catches CatchableError.

When the handler raises a non-CancelledError the flow is:

  1. await protocolHolder.protocol.handler(conn, ms)
  2. The finally block after it
  3. The return, both in successful and in exception case
  4. The outer except CatchableError as exc:, it logs and discards exc
  5. The outer finally: await conn.close()
  6. Stopped multistream handler log, both in successful and exc case.

By changing dcutr/server to only log but not also raise, difference is that the outer except CatchableError in step (4) is skipped.

As that is a redundant log anyway (dcutr/server already logs), it should be fine to not raise. That's in line with all the other protocol handlers (besides tests / examples) and opens up limiting {.raises.} annotation for handlers to just [CancelledError].

`dcutr/server` is the only protocol handler outside tests / examples
that raises exceptions. The only caller of this handler is defined in
`MultStreamSelect.handle`, which has a surrounding `except` block that
catches `CatchableError`.

When the handler raises a non-`CancelledError` the flow is:

1. `await protocolHolder.protocol.handler(conn, ms)`
2. The `finally` block after it
3. The `return`, both in successful and in exception case
4. The outer `except CatchableError as exc:`, it logs and discards `exc`
5. The outer `finally`: `await conn.close()`
6. `Stopped multistream handler` log, both in successful and exc case.

By changing `dcutr/server` to only log but not also raise, difference
is that the outer `except CatchableError` in step (4) is skipped.

As that is a redundant log anyway (`dcutr/server` already logs), it
should be fine to not raise. That's in line with all the other protocol
handlers (besides tests / examples) and opens up limiting `{.raises.}`
annotation for handlers to just `[CancelledError]`.
Copy link

codecov bot commented Mar 11, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 82.57%. Comparing base (08a48fa) to head (869d199).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           unstable    #1063   +/-   ##
=========================================
  Coverage     82.56%   82.57%           
=========================================
  Files            91       91           
  Lines         15814    15812    -2     
=========================================
- Hits          13057    13056    -1     
+ Misses         2757     2756    -1     
Files Coverage Δ
libp2p/protocols/connectivity/dcutr/server.nim 80.00% <50.00%> (-0.86%) ⬇️

... and 2 files with indirect coverage changes

@arnetheduck arnetheduck merged commit 49a92e5 into unstable Mar 12, 2024
10 of 11 checks passed
@arnetheduck arnetheduck deleted the dev/etan/ex-dcutr branch March 12, 2024 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: done
Development

Successfully merging this pull request may close these issues.

2 participants