-
Notifications
You must be signed in to change notification settings - Fork 75
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
Ensure MySQL is only initialized once #465
base: master
Are you sure you want to change the base?
Conversation
Pardon my ignorance on the issue, but will this work on perls build without pthreads? (On recent perls, this now has to be explicitly requested, but it was the default on very old perls) |
Here's an example of a check for whether a Perl has been compiled with pthreads: https://metacpan.org/release/OLEG/Net-DNS-Native-0.22/source/Makefile.PL I do not suggest requiring pthreads as this module does, because it's not central to DBD::mysql's operation. But perhaps this code needs to be conditional on it somehow |
It's certainly possible to do this without pthreads; perhaps the perl runtime or MySQL client library ship with synchronization primitives that could be used but I personally am not familiar enough with them to know if that is the case or not. I used pthreads here because it provided the necessary facility and is, as far as I'm aware, fairly universally available. |
Maybe using diff --git a/dbdimp.c b/dbdimp.c
index 39db033..dff796e 100644
--- a/dbdimp.c
+++ b/dbdimp.c
@@ -1206,7 +1206,6 @@ MYSQL *mysql_dr_connect(
#else
client_flag = CLIENT_FOUND_ROWS;
#endif
- mysql_library_init(0, NULL, NULL);
mysql_init(sock);
if (imp_dbh)
diff --git a/mysql.xs b/mysql.xs
index 6017ed2..ca014b0 100644
--- a/mysql.xs
+++ b/mysql.xs
@@ -31,6 +31,9 @@ INCLUDE: mysql.xsi
MODULE = DBD::mysql PACKAGE = DBD::mysql
+BOOT:
+mysql_library_init(0, NULL, NULL);
+
double
constant(name, arg)
char* name |
Probably not - since each MPM worker thread spawns its own Perl interpreter, It looks like neither Perl's XS interface nor libmysql export any synchronization primitive that can be used here, which is unfortunate. How likely is the situation that somebody uses DBD::mysql with a Perl or system that doesn't have pthreads? Would it be reasonable to add the check (which makes the build fail without pthreads) as suggested above by @Grinnz ? |
It is quite likely on Perls older than 5.20 that DBD::mysql would be used on a Perl without pthreads linked. I don't think it's a good idea to break this configuration. |
I also am not familiar with how pthreads works on Windows, as you can see in the module I linked there is some special casing around that. |
5.20 is over 10 years old now, though. How likely is it to have such an old Perl version with such a new version of DBD::mysql?
pthreads isn't shipped with Windows directly, unlike on Linux where pthreads is pretty much always available when a compiler is available. The module you linked includes the prebuilt lib files for Windows, which is why it has the special case. For something like pthreads, that's probably the simplest working approach that doesn't introduce other additional dependencies. |
For now it looks like:
This seems somewhat similar: https://stackoverflow.com/a/39136689/958681 Note that DBD::mysql on Windows is currently unfortunately mostly not working due to how Perl, MySQL and OpenSSL are build and shipped. However we shouldn't make that even more difficult if we can avoid it. |
I can add an ifdef'd Win32 path that doesn't use pthreads, and otherwise make it spit out a warning without pthreads but still compile. |
The Win32 path I described above would use the I do need to set up a build environment for this, though; Windows programming is my "home territory" for work, but not for the Perl work I do in my free time. I assume it won't be particularly difficult. |
@roavin Please see this comment and the rest of that thread for the current state on Windows. |
See #464
Note that this introduces a pthreads dependency; I don't know if this requires further changes to
Makefile.PL
.