fluffynuts / PeanutButter

Tasty, versatile, nutritious; goes with many things in .net.
BSD 3-Clause "New" or "Revised" License
179 stars 32 forks source link

Possibility of port conflicts #29

Open fluffynuts opened 4 years ago

fluffynuts commented 4 years ago

I've seen a mysql tempdb attempt to start up and fail with this in the error log:

2020-06-12T08:35:11.547292Z 0 [ERROR] Can't start server: Bind on TCP/IP port: No such file or directory
2020-06-12T08:35:11.547717Z 0 [ERROR] Do you already have another mysqld server running on port: 49932 ?

Perhaps TempDbMySql could look for mysql-err.log and try to grok this issue; if found, re-randomize the port and try again.

Exouxas commented 2 years ago

Saw this issue while browsing for stuff to do. Doesn't this commit 79799728d87281aa4b22cc55fbf5b9c1ea263f1a fix this issue? Or does this problem still occur even with the port finder?

fluffynuts commented 2 years ago

I don't see this often, but it's still possible as a race condition, especially if you're setting the TEMPDB_PORT_HINT environment variable (which is really useful if you'd like to connect to the tempdb with other tools whilst debugging). Basically, we select a random port (or the hinted one), test if it's in use (and if it is, re-roll, or, if using the hint, increment), then try to start up mysql - which is not instantaneous. So if you're using the port hint and run test assemblies in parallel, it's quite possible to trigger this; if you're running without the port hint, it's possible, but a lot less likely. Of course, it's also possible that something else grabs the port in the second or two it takes mysql to get up and listening.

At any rate, it would be neat if, upon mysql failing to start, the tempdb wrapper could interrogate the error log, and if it sees a port conflict, try again with a new port. I just haven't gotten around to it yet, and it's infrequent enough that I haven't had my hand forced.