Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Circumventing immutable access introduces race condition in Worker struct #683

Closed
murerfel opened this issue Mar 21, 2022 · 0 comments
Closed
Assignees
Labels
F2-bug Something isn't working

Comments

@murerfel
Copy link
Contributor

Noticed this while debugging another issue.

We circumvent the immutability of an Arc<Worker> by using raw pointer casting:

let maybe_worker = &mut *self.worker.get_mut_worker();
. This introduces race conditions, when access is done from multiple threads (which is the case). That's the reason why Arc<T> only supports immutable functions. If we want to mutate something in the update_peers, the underlying struct must use RwLock to protect against concurrent access.

Fix this by making the methods in

pub trait UpdatePeers {
fn search_peers(&self) -> WorkerResult<Vec<Url>>;
fn set_peers(&mut self, peers: Vec<Url>) -> WorkerResult<()>;
fn update_peers(&mut self) -> WorkerResult<()> {
let peers = self.search_peers()?;
self.set_peers(peers)
}
}
immutable and add locks in the Worker to properly manage access to the peers list.

@murerfel murerfel added the F2-bug Something isn't working label Mar 21, 2022
@murerfel murerfel self-assigned this Mar 21, 2022
murerfel pushed a commit that referenced this issue Mar 30, 2022
* Consistently (re-)use the component container
* RPC server is initialized before registering on the parentchain
* Fix issue with sidechain block import when latest parentchain block is already too new

Closes #545 #600 #684 #683
haerdib added a commit to ajuna-network/worker that referenced this issue May 9, 2022
* Add a local-setup config to the tutorial (integritee book) (integritee-network#666)

* Update call status to `InSidechainBlock` only after block import (integritee-network#676)

* rename on_block_created to on_block_imported

* update tx status only after block import

* fix clippy

* fix cargo test

* remove waiting time from demos

* readd removed comments

* udpate comments

* extract call removal logic from on_block_imported

* Bump substrate to commit f5f286db0da9... (integritee-network#669)

* Bump substrate

Bump substrate to commit 8df8d908c4d77a8dd19751784b6aca62159ddda8

Remove dependencies of scale-info 1.0.0 and parity-scale-codec 2.3.1

Upgrade substrate to commit f5f286d... substrate fix for : sp-core's full_crypto feature flag breaks no_std builds

* frame-metadata from crates.io

* Update CI to use updated node

Co-authored-by: echevrier <[email protected]>

* Dockerize (integritee-network#668)

* Dockerize the binaries integritee-network#579

* Add tags to run as well integritee-network#579

* Fix running binary in docker integritee-network#579

* Add more files to docker integritee-network#579

* Add conditional runs

* Add +x earlier

* Rename docker-service to integritee-demo-validateer. Fixes integritee-network#579

* Lift clap to version 3.16 and move stf cli to cli crate. (integritee-network#679)

* Lift clap to version 3.16 and move stf cli to cli crate.

* Adapt demo script parameters

* Add cli examples to README.md

* update comment descriptions

Co-authored-by: Gaudenz Kessler <[email protected]>

* Refactor global components and initialization process (integritee-network#677)

* Consistently (re-)use the component container
* RPC server is initialized before registering on the parentchain
* Fix issue with sidechain block import when latest parentchain block is already too new

Closes integritee-network#545 integritee-network#600 integritee-network#684 integritee-network#683

* create alive service to deterine that the service is up, running and registered (integritee-network#697)

* create alive service

* replace alive with initialized

Co-authored-by: Gaudenz Kessler <[email protected]>

* Add port config for the untrusted http server for `is_initialized` (integritee-network#700)

* rename wrong `signing_key` function name to `state_key` (integritee-network#704)

* Move top pool and top pool author crates to core primitives (integritee-network#705)

* Introduce state snapshot history (integritee-network#698)

Closes integritee-network#688

* Add header to sidechain block (integritee-network#699)

Closes integritee-network#686 

Co-authored-by: Gaudenz Kessler <[email protected]>

* introduce layer for indirection for sidechainblock (integritee-network#716)

Closes integritee-network#710 

Co-authored-by: Gaudenz Kessler <[email protected]>
Co-authored-by: Felix Müller <[email protected]>

* Persist web-socket connections (integritee-network#718)

Complete overhaul of the trusted web-socket server:
* using MIO to serve concurrent connections
* Server keeps connections open until a client requests a close
* Changed our clients to match this pattern

* Upgrade to polkadot v0.9.19 (integritee-network#720)

* Bump substrate to polkadot-v0.9.19
Bump RUNTIME_SPEC_VERSION to 9

Set substrate-api-client to polkadot-v0.9.19
Set integritee-node to polkadot-v0.9.19

Set integritee-node to master

* Cargo update + reabse

* Update github actions

Co-authored-by: echevrier <[email protected]>

* fix some cargo.tomls

* fix cargo.lock

* remove game engine

* update teerex module

* fix itp-registry-storage

* cargo update

* resinsert game engine

* some further clean up

* update teaclave

* add ajuna commands

* cargo update

* carog update

* update ajuna cli

* fix some thins

* Signed sidechain block

* fix shard_id getter

* fix load_initialized

* fix sgx externalities import

* fix compilation issues

* remove patches and cargo update

* update demo docu

* add bin folder to docu

* remove hard coded ports. Not necesasry

* add ./

* update pallet verions

* make tests compile again

* fix import in sgx mode

* merge from upstream number two.. remove itp storage verifier

* cargo fmt

* fix tests

* update doc once again

* fix script and queue game

* cargo update + some code clean up

Co-authored-by: Felix Müller <[email protected]>
Co-authored-by: echevrier <[email protected]>
Co-authored-by: echevrier <[email protected]>
Co-authored-by: mosonyi <[email protected]>
Co-authored-by: gaudenzkessler <[email protected]>
Co-authored-by: Gaudenz Kessler <[email protected]>
Co-authored-by: Felix Müller <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F2-bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant