Repository navigation
[python] Keep RESTTokenFileIO usable in a forked child - #10556
Merged
Merged
Conversation
Since apache#10552, RESTTokenFileIO creates FileIOs under one process-wide lock. If the process forks while another thread holds that lock, for example while that thread creates a FileIO, the child inherits the lock in its held state and its first file_io() call blocks forever, whatever table it is for. The per-object lock and the per-table token lock, held while a token is refreshed, have had the same problem since before apache#10552. Do what the logging module does: hold the cache lock across fork, so the child gets the cache in a consistent state, and give the child new token locks and per-object locks. Python 3.6 has no os.register_at_fork and behaves as before.
Contributor
|
+1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Follow-up to #10552.
RESTTokenFileIOnow looks up and creates FileIOs under one process-wide lock. If the process forks while another thread holds that lock, for example while that thread creates a FileIO, the child inherits the lock in its held state. The child's firstfile_io()call then blocks forever, whatever table it is for. Before #10552 the lock was per object, so only a child that used that same object could block.The per-object lock and the per-table token lock have the same problem when a fork happens during a token refresh. That was already the case before #10552.
This pull request handles these locks the way the
loggingmodule handles its locks:fork(os.register_at_fork). A fork waits for an in-progress lookup or FileIO creation, so the child sees the cache in a consistent state.RESTTokenFileIOobject, which are tracked in aWeakSet.Python 3.6 has no
os.register_at_forkand behaves as before.Tests
rest_token_file_io_test.pytest_fork_while_another_thread_creates_file_io: another thread is creating a FileIO when the process forks. The child looks up another table and finds the FileIO that was being created already cached.test_fork_while_another_thread_refreshes_token: another thread is refreshing a token, so it holds the object's lock and the table's token lock, when the process forks. The child uses that object and a new object of the same table.dev/cfg.inipasses.Verified with forks and JindoSDK
A probe forks children that use
RESTTokenFileIOwhile another thread is busy in it. It uses local tables, because a forked child cannot use pyjindo once the parent has used it, with or without this change.The pyjindo e2e scenarios of #10552 (pyjindosdk 6.10.4 against a local OSS-compatible server: streams open across token refreshes, concurrent readers, Avro and Parquet table reads and writes, injected 503s and dropped connections, normal and atexit exits,
spawnchildren) were rerun with this change, and all pass.API and Format
No.
Documentation
No.