FoundationDB

Fork and indefinite blocking of fdb_future_block_until_ready


(Cloudspeech) #1

Hi,

I tried to couple a (pre)forking socket server with foundationDB, using the C API directly.

The socket server is a slight modification of https://gist.github.com/paulsmith/204301
for unix domain sockets.

A client connects with an input that ultimately translates into a key to be looked up in a foundationDB database.

Using a variation of function getKey in

I intended to send the value corresponding to the key back to the client.

Everything works as intended when I disable forking alltogether.

However, with fork() enabled in the server code, the execution blocks indefinitely at the first fdb_future_block_until_ready invocation.

Questions: Is this expected behaviour? What are best practices to provide a concurrent socket interface to foundationDB using the low-level C API?


(Alex Miller) #2

This would be easier to answer if you posted your code. I’m going to guess that the problem is that FoundationDB starts up a background thread which runs significant pieces of the client code, and multiple threads and fork do not play together well.

If you flip your code to spawning a new thread for each connection instead of forking, do things then work?


(Cloudspeech) #3

Thanks for the hints!

Yes, indeed the problem was about the mixing of fork (my code) and thread creation (in foundationDB init).

Cf. https://thorstenball.com/blog/2014/10/13/why-threads-cant-fork/ for a brief discussion.

The solution in my case was to init foundationDB late, i.e. in each fork()ed child.