Bug #93646 | mysqlx_session_valid() results in Segmentation fault | ||
---|---|---|---|
Submitted: | 17 Dec 2018 19:25 | Modified: | 18 Nov 2019 18:45 |
Reporter: | Daniël van Eeden (OCA) | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | Connector / C++ | Severity: | S3 (Non-critical) |
Version: | 8.0.13 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[17 Dec 2018 19:25]
Daniël van Eeden
[18 Dec 2018 11:36]
MySQL Verification Team
Hi Daniel, Session handle becomes invalid after close as the memory is freed hence the crash. Our team will decide how to proceed. Thanks for the report Bogdan
[18 Dec 2018 13:26]
Daniël van Eeden
Setting sess to NULL seems to work. Not sure if that's the best solution. ----- #include <mysqlx/xapi.h> int main() { mysqlx_session_t *sess = mysqlx_get_session_from_url("mysqlx://msandbox:msandbox@localhost/test", NULL, NULL); mysqlx_session_valid(sess); mysqlx_session_close(sess); sess = NULL; mysqlx_session_valid(sess); }
[20 Dec 2018 9:54]
Rafal Somla
To be precise, after closing a session, the session is simply destroyed and no longer exists. The handle to the session (the mysqlx_session_t* pointer) becomes invalid or "dangling", similar like a pointer after a call to free(). Function mysqlx_session_valid() function does not check validity of the session handle, but of the session itself - it assumes that session handle you pass to it is valid. From that perspective, your second call to mysqlx_session_valid() is trying to check validity of a session that does not exist any more... Since it is plain C, we don't think we can detect if pointer is dangling or not - the best we can do is "undefined behavior", i.e., crash in this case.
[20 Dec 2018 20:10]
Daniël van Eeden
In that case the second option I suggested seems to be the correct one: Update the documentation to say that mysqlx_session_close() invalidates the session and that it must not be used afterwards. I think mysqlx_session_close() should have been called mysqlx_session_free() to be more explicit about what it does. But I guess it's too late to change that now.
[15 Nov 2019 13:22]
Rafal Somla
Posted by developer: Doxygen documentation for the relevant functions was updated to clearly inform that the functions invalidate handles which cannot be used afterwards. Note: No functionality was changed - it is only a documentation update.
[18 Nov 2019 18:45]
Paul DuBois
Posted by developer: Documentation update only. No changelog entry required.