-
Type: Bug
-
Resolution: Unresolved
-
Priority: Minor - P4
-
None
-
Affects Version/s: WT3.2.1, WT10.0.0
-
Component/s: None
We would like to ask clarification about the "thread-safe" property of WT_SESSION::strerror function.
In the documentation of wiredtiger_strerror there is a note about that the WT_SESSION::strerror maybe thread-safe (both for 3.2.1 and 10.0.1):
(see WT_SESSION::strerror for a thread-safe API).
https://source.wiredtiger.com/develop/group__wt.html#gae8bf720ddb4a7a7390b70424594c40fd
https://source.wiredtiger.com/3.2.1/group__wt.html#gae8bf720ddb4a7a7390b70424594c40fd
In the implementation of WT_SESSION::strerror there is a direct call of wiredtiger_strerror. Because of that the WT_SESSION::strerror seems to be not thread-safe.
In os_errno.c:
const char * __wt_strerror(WT_SESSION_IMPL *session, int error, char *errbuf, size_t errlen) { const char *p; /* * Check for a WiredTiger or POSIX constant string, no buffer needed. */ if ((p = __wt_wiredtiger_error(error)) != NULL) return (p);
An example code that demonstrates the problem is the following:
#include <stdio.h> #include <pthread.h> #include <string.h> #include "wiredtiger.h" WT_CONNECTION *conn = NULL; void *thread(void *args) { int r = 0; WT_SESSION *thread_session = NULL; r = conn->open_session(conn, NULL, NULL, &thread_session); printf("thread wiredtiger_session: %d\n", r); const char *s = thread_session->strerror(thread_session, 2000); printf("thread s: %p : %s\n", s, s); return NULL; } int main() { WT_SESSION *main_session = NULL; int r = 0; r = wiredtiger_open("WT_HOME", NULL, "create", &conn); printf("wiredtiger_open: %d\n", r); r = conn->open_session(conn, NULL, NULL, &main_session); printf("main wiredtiger_session: %d\n", r); const char *s = main_session->strerror(main_session, 3000); pthread_t t; pthread_create(&t, NULL, thread, NULL); pthread_join(t, NULL); printf("main s: %p : %s\n", s, s); conn->close(conn, NULL); return 0; }
Output:
wiredtiger_open: 0 main wiredtiger_session: 0 thread wiredtiger_session: 0 thread s: 0xa0f460 : Unknown error 2000 main s: 0xa0f460 : Unknown error 2000
Note that both error strings are the same. If the WT_SESSION::strerror is thread-safe then the expected behavior would be to get the two different error strings ( "Unknown error 2000" and " Unknown error 3000").