-
-
Notifications
You must be signed in to change notification settings - Fork 48
Added RFC for network errors handling #78
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
Open
zevlg
wants to merge
5
commits into
ponylang:main
Choose a base branch
from
zevlg:network-errors-handling
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| - Feature Name: network errors handling | ||
| - Start Date: 2017-02-15 | ||
| - RFC PR: (leave this empty) | ||
| - Pony Issue: (leave this empty) | ||
|
|
||
| # Summary | ||
|
|
||
| Provide API for handling network errors. | ||
|
|
||
| # Motivation | ||
|
|
||
| Current interfaces, such as `TCPListenNotify`, `TCPConnectionNotify` | ||
| and `UDPNotify` do not provide any information about why some action | ||
| has failed. This makes it difficult to figure out software | ||
| configuration errors. Knowledge about nature of network failure is | ||
| essential for production software. | ||
|
|
||
| # Detailed design | ||
|
|
||
| 1. Create a primivite union of possible network errors, similar to | ||
| `FileErrNo`, that maps a platform specific errno codes on these | ||
| primitive values. | ||
|
|
||
| ```pony | ||
| type SocketErrNo is | ||
| ( SocketOK | ||
| | SocketError | ||
| | SocketInUse | ||
| | SocketConnRefused | ||
| | SocketNetUnreach | ||
| | SocketTimeout | ||
| ) | ||
| ``` | ||
|
|
||
| Where: | ||
|
|
||
| * `SocketOK' - success | ||
| * `SocketInUse` - local address is already in use | ||
| * `SocketConnRefused` - no-one listening on the remote address | ||
| * `SocketNetUnreach` - no routing to remote host | ||
| * `SocketTimeout` - timeout while attempting connection | ||
|
|
||
| 2. Add private `_errno` field of `SocketErrNo` type into | ||
| `TCPConnection`, `UDPSocket` and `TCPListener`. On failure, set | ||
| `_errno` using corresponding OS errno code fetched using `SO_ERROR` | ||
| socket option | ||
|
|
||
| 3. Create publically available method `errno` which returns `_errno`, | ||
| for example: | ||
|
|
||
| ```pony | ||
| fun errno(): SocketErrNo => | ||
| """ | ||
| Returns the last error code set for this socket | ||
| """ | ||
| _errno | ||
| ``` | ||
|
|
||
| # How We Teach This | ||
|
|
||
| Update the doc strings for `TCPConnectionNotify.connect_failed`, | ||
| `UDPNotify.not_listening` and `TCPListenNotify.not_listening` | ||
| describing error fetching mechanism described in Design section. | ||
|
|
||
| Code example, showing usage of handling errors, is highly encouraged. | ||
|
|
||
| # How We Test This | ||
|
|
||
| Add test case of making invalid connection, checking that errno is set | ||
| uppon call to notifier. | ||
|
|
||
| # Drawbacks | ||
|
|
||
| Requires changes in `libponyrt/lang/socket.c` since actual value for | ||
| `SO_ERROR` is not exposed to pony level. | ||
|
|
||
| # Alternatives | ||
|
|
||
| Extend notifiers API, so error code is provided uppon call to | ||
| notifier. This approach looks not that smooth to integrate as | ||
| proposed in Design section. | ||
|
|
||
| # Unresolved questions | ||
|
|
||
| How proposed API conforms with [RFC 23](https://github.com/ponylang/rfcs/blob/master/text/0023-network-dont-provide-default-implementation-for-failures.md) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On success, we'd also want to set it back to
SocketOK, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, on any outcome (success or failure) we want to set
_errno. I'll fix