square / square/pylink

Race condition when accessing library

Open
#4 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug good first issue
Dominant language
Python
Stars
430
Forks
151
Avg merge
5d 3h
Merged PRs (30d)
1

Description

Description

We create a temporary file that is a copy of the library when we instantiate a Library instance. This is necessary to avoid a bug in the software that prevents accessing multiple hardware peripherals in a single process. On rare occasions, dlopen will fail with an error along the lines of No Suitable Image found. It seems to best resemble this GRPC issue #5568. The solution seems to be forcing the file to be committed to disk through an atomic write.

Suggested Changes

  • Use fsync after os.write when creating a JLock object.
  • Flush the outputfile created in Library.load after write, then before closing the temporary file, call fsync on it.
  • Add a test to catch this behaviour before the patch, then ensure it's fixed after the patch.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the code that creates a JLock object and the Library.load path that writes the temporary library file. Reproduce or add a test for the intermittent dlopen failure, then verify that the file is flushed and synchronized before it is closed and accessed.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
embedded-iot
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.