On 2007-08-28 21:09:40 +0200, Ernesto wrote: > Jens Weibler wrote on 28.08.2007 19:41: > >Ernesto wrote: > >>Jens Weibler wrote on 28.08.2007 08:27: > >>>Ernesto wrote: > >>>>*check_user* > >>> > >>>Do I see it right, that you're sharing one mysql-connection for > >>>all connections? > >> > >>Yes. > >> > >>>What about threaded qpsmtpd? > > > >mmh, I think the problem is that two threads could execute a query > >over one connection at the same time. > > I think, that the database engine will keep track about the queries.
It can't. Think of it this way: You have two threads (or processes, it doesn't matter) which share a common connection. Both send a query to the server at about the same time. Here's the first problem: Stream sockets are streams of bytes, not packets. The server might receive part of the first query, then the second query, then the rest of the first query. But since queries are relatively short, it will probably receive two separate queries. Now the server starts processing these queries and in the meantime the two client threads start a read (or recv) call. After some time the server will have the first results and send them through the connection - but there are two receivers on that connection - which one will receive it? You can't tell, and there's a 50% chance that it's the wrong one. > And for MySQL the Perl fork seems to close the connection, That might be a side-effect of the parent closing the connection (if it does this) or the MySQL client library detecting the fork and closing the connection to prevent the scenario I outlined above. Generally you cannot expect a DBI database handle to be useful after a fork. > therefore mysql_auto_reconnect has to be used. So, if you have to reconnect anyway, why not explicitely connect in connect_hook? It won't be slower and it will work with other databases. hp -- _ | Peter J. Holzer | I know I'd be respectful of a pirate |_|_) | Sysadmin WSR | with an emu on his shoulder. | | | [EMAIL PROTECTED] | __/ | http://www.hjp.at/ | -- Sam in "Freefall"
signature.asc
Description: Digital signature