Repository navigation
Conversation
Use a short timeout after receiving a notification for the notification thread. Add a hack/workaround for a bug in SslStream caused by Socket read timeout.
|
Hi,glenebob I am just interested in this issue.Please let me say my viewpoint. Moreover, i propose that while the notification thread hold the lock, the calling of Socket.Poll() should return as soon as possible , so normal connection thread could has chance to gain the lock soon. the pseudo code just like this: *) Occasionally Npgsql will throw “This stream does not support seek operations”exception.The reason is just like the following |
|
Sorry, Francisco and I had a long discussion about this, unfortunately in private. My comment about implementing our own stream was naive. It doesn't help, because the streams upon which it would rely don't all provide the ability to query for buffered data. The correct fix is to have only one thread reading the network stream, but rearranging the code to work that way is quite involved. I haven't yet figured out a sensible path from here to there. Essentially, what is now the notification thread would become the One True socket reader. The user thread that calls Npgsql to execute queries would never read the socket, instead it would wait for events delivered by the reader thread. A nice side effect of this, is that we could support async query execution for almost free. With the current architecture, the best way to fix the problem that I can see is the time out solution I came up with, but as you can see, that is very messy due to the timeout bug in SslStream. As to your comment about Poll() and Sleep(), look at PR #61. The need for Sleep() is eliminated by using the proper thread synchronization mechanism for the problem. There's a comment there that explains a bit more. -Glen |
Hi Francisco,
Here's what I did to fix the multiple async notification bug, for discussion.
It might actually be better to roll our own buffered stream, or do what we talked about with binary readers, where we can peek at the buffer. Then if we peek and there's data, go ahead and read notifications, else do the Poll call.
The way I did it here was quite simple, until I ran into the timeout bug.
-Glen