Race condition in Protocols.HTTP.Session

Imported from https://youtrack.roxen.com/issue/PIKE-148

Reported by Martin Karlgren marty@roxen.com

Related to PIKE-239

It seems there's some kind of race condition in Protocols.HTTP.Session, related to reused SessionQuery objects. The KeptConnection class is probably involved.

Maybe the connection reuse handling should be revamped, also considering the issue in WS-389. Seems somewhat redundant (and error-prone) to keep entire Query objects around, why not just keep the q->con (i.e. Stdio.File or similar) in the cache?

Indexing the NULL value.
 6:03:07            : pike/lib/modules/Protocols.pmod/HTTP.pmod/Session.pike:667: HTTPClient.Session()->give_me_connection(URI("http://roxen-appl-community-test-archive.roxen.com/storage/rxnfs/community45/92/09/318e-0a91-41c1-9088-26ccbb35ba9f/pp.jpg"))
 6:03:07            : pike/lib/modules/Protocols.pmod/HTTP.pmod/Session.pike:83: Request("http://roxen-appl-community-test-archive.roxen.com/storage/rxnfs/community45/92/09/318e-0a91-41c1-9088-26ccbb35ba9f/pp.jpg" - no connection)->prepare_method("PUT",@0=URI("http://roxen-appl-community-test-archive.roxen.com/storage/rxnfs/community45/92/09/318e-0a91-41c1-9088-26ccbb35ba9f/pp.jpg"),UNDEFINED,mapping[2],,,0)
 6:03:07            : pike/lib/modules/Protocols.pmod/HTTP.pmod/Session.pike:885: HTTPClient.Session()->async_do_method_url("PUT",@1=URI("http://roxen-appl-community-test-archive.roxen.com/storage/rxnfs/community45/92/09/318e-0a91-41c1-9088-26ccbb35ba9f/pp.jpg"),UNDEFINED,,,5)
 6:03:07            : etc/modules/HTTPClient.pmod:536: HTTPClient.Session()->async_do_method_url("PUT",@5=URI("http://roxen-appl-community-test-archive.roxen.com/storage/rxnfs/community45/92/09/318e-0a91-41c1-9088-26ccbb35ba9f/pp.jpg"),UNDEFINED,,,5)
 6:03:07   1m24.1s  : etc/modules/HTTPClient.pmod:166: HTTPClient.do_safe_method("PUT",@10=URI("http://roxen-appl-community-test-archive.roxen.com/storage/rxnfs/community45/92/09/318e-0a91-41c1-9088-26ccbb35ba9f/pp.jpg"),HTTPClient.Arguments(),1,HTTPClient.Session())
 6:03:07            : etc/modules/HTTPClient.pmod:110: HTTPClient.async_put(@10,@11=HTTPClient.Arguments(),@12=HTTPClient.Session())