[SERVER-50253] errno-style handlers conflate error categories Created: 11/Aug/20  Updated: 29/Oct/23  Resolved: 28/Apr/22

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: None
Fix Version/s: 6.1.0-rc0

Type: Bug Priority: Major - P3
Reporter: Billy Donahue Assignee: Billy Donahue
Resolution: Fixed Votes: 0
Labels: servicearch-wfbf-sprint
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-41353 Fix late calls to errnoWithDescription() Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

There's sloppy conflation of errno with GetLastError codes, and possibly more error code spaces like asio, ssl.

Win32 has both an errno int (signed 32-bit) and a GetLastError DWORD (unsigned 32-bit). They aren't in the same number space, and a DWORD can't be portably stored into a signed int without special care (which we aren't taking). I correctly get compiler errors from the narrowing conversions of DWORD to int after textually replacing errnoWithDescription(e) expressions to Errno{e}.desc() expressions. Braced-init doesn't tolerate narrowing!

Logically, a function called errnoWithDescription should only be looking at errno codes, but we have it so that it does a GetLastError on Win32, and there is no helper function analyze the `errno` codes (as set by _read, etc) on Win32. We need to keep GetLastError and errno regimes separated to do this right. We'll have clearer and more correct error handling.

C++11's <system_error> introduced std::error_code which separates errors into an {int, category} pair, so these can be kept straight. It also introduces a clear lossless exception type for std::error_code, called std::system_error. What we usually do in mongo code is a kind of punt where we try to uassert to convert any system errors into DBException on the way up.

The system_error API.

https://en.cppreference.com/w/cpp/header/system_error

Discussion of system_error, some problems (you have to be careful with it, so maybe we write wrappers), and forward-looking solutions for it.

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0824r1.html



 Comments   
Comment by Billy Donahue [ 28/Apr/22 ]

fixed by SERVER-41353

Comment by Lauren Lewis (Inactive) [ 21/Dec/21 ]

We haven’t heard back from you in at least 1 year, so I'm going to close this ticket. If this is still an issue for you, please provide additional information and we will reopen the ticket.

Comment by Mark Benvenuto [ 11/Aug/20 ]

Windows has several different error code categories:
NTSTATUS - https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/596a1078-e883-4972-9bbc-49e60bebca55
HRESULT - https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/0642cb2f-2075-4469-918c-4441e69c548a
Win32 Error Codes - https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/18d8fbe8-a967-4f1c-ae50-99ca8e491d2d

You can convert between them in some cases if you use the right functions to do the conversion. Various subsystems declare their own types like SECURITY_STATUS.

Generated at Thu Feb 08 05:22:11 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.