Skip to content

Conversation

@sfc-gh-anoyes
Copy link
Collaborator

As described in https://apple.github.io/foundationdb/api-c.html?highlight=fdb_future_block_until_ready#c.fdb_future_block_until_ready, it's an error to call fdb_future_block_until_ready from the main thread (the one running fdb_run_network). This PR changes the current behavior of deadlocking (difficult to debug and to know what to do to recover from it) to throwing an error and tracing a diagnostic.

I'm also wondering if it would be even better to have a new error code for this, in case the client doesn't have tracing enabled.

Also fix a data race that apparently hasn't been ported to 6.2 yet
@sfc-gh-tclinkenbeard
Copy link
Collaborator

The C API documentation should also be updated to reflect this change.

@ajbeamon
Copy link
Contributor

I would be in favor of a new error code if you want to add one. Either that, or I guess we could try to make it consistent how we report the failure for these generic errors. I've found it's sometimes been difficult trying to help someone else diagnose errors like client_invalid_operation if they aren't already fairly experienced with FDB, and that probably ends up giving them a bad impression too.

@sfc-gh-anoyes
Copy link
Collaborator Author

I'll update the documentation and add a new error code

@sfc-gh-anoyes
Copy link
Collaborator Author

The C API documentation should also be updated to reflect this change.

I'm not sure how exactly to change it. It's accurate as is, and I don't want to encourage anyone to rely on the new "throws a particular error" behavior

@sfc-gh-tclinkenbeard
Copy link
Collaborator

From the C API documentation:

fdb_future_block_until_ready() will return an error only in exceptional conditions (e.g. out of memory or other operating system resources).

This is no longer accurate, you can also throw an error if you call this from the main thread.

Never call this function from a callback passed to fdb_future_set_callback(). This may block the thread on which fdb_run_network() was invoked, resulting in a deadlock.

The advice still holds, but this won't cause deadlock anymore.

@sfc-gh-anoyes
Copy link
Collaborator Author

I'm going to change this so that it only throws if the future is not ready, since it's possible that there are users who rely on the current behavior of fdb_future_block_until_ready not blowing up if you call it from the network thread and it's ready (even though the documentation advises against that)

@ajbeamon ajbeamon merged commit 96a39d6 into apple:release-6.2 Sep 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants