Subject | fbclient and thread-safety |
---|---|
Author | precari0 |
Post date | 2006-09-12T14:36:12Z |
Hi!
I´m having problems with a multi-threaded middle-tier I´m working on.
Every now and then I get "invalid request handle" errors. At first I
thought I could be messing with the connection pool and two threads
could be trying to use the same connection at the same time. But after
a deeper analisys I realize that is not the problem. Imagine the
following:
- Thread T1 creates connection C1 and uses it for some select/update.
- C1 returns to the pool, waiting for new requests.
- Thread T2 uses C1 for some operations.
- C1 is in use by T2, a new request arrives.
- Now T3 creates C2 and uses it for some operations.
- C1 returns to the pool.
- C2 returns to the pool.
Is this sequence correct from a thread-safe perspective? Should it work?
If this kind of sequence goes on for a while, the "invalid request
handle" appears. But if I change my app so that every thread gets its
own unique connection, the problem doesn´t happen. For example:
- Thread T1 creates connection C1 and uses it for some select/update
- C1 *does not* return to the pool, it is locked to T1
- T2 creates C2, uses it for some operations and keeps it for later use
- T3 creates C3, uses it for some operations and keeps it for later use
It seems to me that it has something to do with the connection being
created by a certain thread and later on being used by another thread.
How can I track down this problem? I thought of posting a stack-trace
including fbclient´s stack but I don´t know how to do it.
The problem happens with FB 1.0.3, 1.5.3, 2.0RC3 and RC4.
I´m using Delphi 6.
The connection pool is RemObjects´s DataAbstract.
The problem happens with FIBPlus, IBObjects and IBX.
Any help greatly appreciated.
Thanks and sorry my poor English.
[]s
Douglas
I´m having problems with a multi-threaded middle-tier I´m working on.
Every now and then I get "invalid request handle" errors. At first I
thought I could be messing with the connection pool and two threads
could be trying to use the same connection at the same time. But after
a deeper analisys I realize that is not the problem. Imagine the
following:
- Thread T1 creates connection C1 and uses it for some select/update.
- C1 returns to the pool, waiting for new requests.
- Thread T2 uses C1 for some operations.
- C1 is in use by T2, a new request arrives.
- Now T3 creates C2 and uses it for some operations.
- C1 returns to the pool.
- C2 returns to the pool.
Is this sequence correct from a thread-safe perspective? Should it work?
If this kind of sequence goes on for a while, the "invalid request
handle" appears. But if I change my app so that every thread gets its
own unique connection, the problem doesn´t happen. For example:
- Thread T1 creates connection C1 and uses it for some select/update
- C1 *does not* return to the pool, it is locked to T1
- T2 creates C2, uses it for some operations and keeps it for later use
- T3 creates C3, uses it for some operations and keeps it for later use
It seems to me that it has something to do with the connection being
created by a certain thread and later on being used by another thread.
How can I track down this problem? I thought of posting a stack-trace
including fbclient´s stack but I don´t know how to do it.
The problem happens with FB 1.0.3, 1.5.3, 2.0RC3 and RC4.
I´m using Delphi 6.
The connection pool is RemObjects´s DataAbstract.
The problem happens with FIBPlus, IBObjects and IBX.
Any help greatly appreciated.
Thanks and sorry my poor English.
[]s
Douglas