bryancall opened a new pull request, #13240:
URL: https://github.com/apache/trafficserver/pull/13240
## Problem
Reported in #13203. On FreeBSD (and macOS) Traffic Server logs connection
failures with a misleading errno name, e.g.:
```
CONNECT: attempt fail [CONNECTION_ERROR] to 72.167.35.147:443 for
host='docs.trafficserver.apache.org' connection_result=ENOSTR [60] error=ENOSTR
[60] retry_attempts=0 url='...'
```
`ENOSTR` ("Not a STREAM", an XSI STREAMS error) has nothing to do with the
actual failure, which made these logs confusing to diagnose. The numeric
value
`[60]` is correct; only the symbolic name is wrong.
## Root cause
`swoc::bwf::Errno`'s short name used a single, hardcoded, Linux-numbered
table
indexed directly by the raw errno value:
```cpp
static const std::array<std::string_view, 134> ERRNO_SHORT_NAME = {
"SUCCESS", "EPERM", ... };
auto errno_short_name = [](unsigned n) { return ERRNO_RANGE.contains(n) ?
ERRNO_SHORT_NAME[n] : "Unknown"sv; };
```
errno numbering differs across platforms. Value 60 is `ENOSTR` on Linux but
`ETIMEDOUT` on FreeBSD/macOS (and `ENOSTR` is not defined at all on FreeBSD).
So a genuine connection timeout (`ETIMEDOUT`, errno 60) was printed as
`ENOSTR`. The numbering starts diverging at errno 11 and disagrees on roughly
70 of the values shared between Linux and the BSD-derived platforms, so this
was not a one-off.
## Fix
Replace the single table with a per-platform table, each generated from that
platform's own `<errno.h>`, still looked up by O(1) direct index:
- `#if defined(__linux__)` / `#elif defined(__APPLE__)` / `#elif
defined(__FreeBSD__)`.
- Gaps in the numbering are empty entries that fall through to `"Unknown"`.
- An unsupported platform is a hard `#error` rather than silently wrong
names.
- The `std::error_code` formatter that shared the old table now routes
through
the same function.
The long form (`{::l}`) was already correct because it uses `strerror()`;
this
only affects the symbolic short name. (Also drops a stray trailing space in
the
old `"E2BIG "` entry.)
## Testing
Compiled and verified on Linux, macOS, and FreeBSD 14.3. `bwf::Errno(60)` now
prints:
| Platform | before | after |
| --- | --- | --- |
| Linux | `ENOSTR` | `ENOSTR` (unchanged; 60 really is ENOSTR there) |
| FreeBSD / macOS | `ENOSTR` | `ETIMEDOUT` |
Reproduced the original report on FreeBSD 14.3 against the 10.1.0 release: a
connection that timed out and logged `connection_result=ENOSTR [60]` now
reports `ETIMEDOUT [60]`.
Fixes #13203
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]