openethereum/parity
cheme c1aed4af45 Fix light client deadlock (#9385)
This PR is fixing deadlock for #8918 

It avoids some recursive calls on light_sync by making state check optional for Informant.

The current behavior is to display the information when informant checks if block is major version.
This change a bit the informant behavior, but not on most cases.

To remember where and how this kind of deadlock are likely to happen (not seen with Parkinglot deadlock detection because it uses std condvar), I am adding a description of the deadlock.
Also, for the reviewers there may be better solution than modifying the informant.

### Thread1 

- ethcore/sync/light_sync/mod.rs

A call to the light handler through any Io (having a loop of rpc query running on like client makes the dead lock way more likely).
At the end of those calls we systematically call `maintain_sync` method.

Here maintain_sync locks `state` (it is the deadlock cause), with a write purpose

`maintain_sync` -> `begin_search` with the state locked open

`begin_search` -> lightcliennt `flush_queue` method

- ethcore/light/src/client/mod.rs

`flush_queue` -> `flush` on queue (HeaderQueue aka VerificationQueue of headers)

- ethcore/src/verification/queue/mod.rs

Condition there is some unverified or verifying content

`flush` wait on a condvar until the queue is empty. The only way to unlock condvar is that worker is empty and unlock it (so thread 2 is Verification worker).

### Thread2

A verification worker at the end of a verify loop (new block).

- ethcore/src/verification/queue/mod.rs

thread loops on `verify` method.

End of loop condition is_ready -> Import the block immediately 

calls `set_sync` on QueueSignal which send a BlockVerified ClientIoMessage in inner channel (IoChannel of ClientIoMessage) using `send_sync`

- util/io/src/service_mio.rs

IoChannel `send_sync` method calls all handlers with `message` method; one of the handlers is ImportBlocks IoHandler (with a single inner Client service field)

- ethcore/light/src/client/service.rs

`message` trigger inner method `import_verified`

- core/light/src/client/mod.rs

`import_verified` at the very end notify the listeners of a new_headers, one of the listeners is Informant `listener` method

- parity/informant.rs

`newHeaders` run up to call to `is_major_importing` on its target (again clinet)

-  ethcore/sync/src/light_sync/mod.rs

Here `is_major_importing` tries to get state lock (read purpose only) but cannot because of previous state lock, thus deadlock
2018-09-04 15:36:34 +01:00
..
cli Add POA Networks: Core and Sokol (#9413) 2018-08-30 21:32:47 +02:00
db db: remove wal disabling / fast-and-loose option. (#8963) 2018-07-10 17:33:25 +02:00
light_helpers Update license header and scripts (#8666) 2018-06-04 10:19:50 +02:00
account.rs Add type for passwords. (#8920) 2018-06-22 15:09:15 +02:00
blockchain.rs decode block rlp less often (#9252) 2018-08-02 10:20:46 +01:00
cache.rs Update license header and scripts (#8666) 2018-06-04 10:19:50 +02:00
configuration.rs Added --tx-queue-no-early-reject flag to disable early tx queue rejects (#9143) 2018-07-24 16:04:48 +03:00
deprecated.rs Remove node-health (#9119) 2018-07-18 16:27:29 +02:00
export_hardcoded_sync.rs Remove the dapps system (#9017) 2018-07-11 12:19:54 +02:00
helpers.rs Avoid using $HOME if not necessary (#9273) 2018-08-03 09:58:59 +02:00
informant.rs Fix light client deadlock (#9385) 2018-09-04 15:36:34 +01:00
ipfs.rs Update license header and scripts (#8666) 2018-06-04 10:19:50 +02:00
lib.rs Allow setting the panic hook with parity-clib (#9292) 2018-08-10 11:06:30 +02:00
main.rs Allow setting the panic hook with parity-clib (#9292) 2018-08-10 11:06:30 +02:00
modules.rs Update license header and scripts (#8666) 2018-06-04 10:19:50 +02:00
params.rs Add POA Networks: Core and Sokol (#9413) 2018-08-30 21:32:47 +02:00
presale.rs Add type for passwords. (#8920) 2018-06-22 15:09:15 +02:00
rpc_apis.rs Remove node-health (#9119) 2018-07-18 16:27:29 +02:00
rpc.rs Remove the dapps system (#9017) 2018-07-11 12:19:54 +02:00
run.rs Add POA Networks: Core and Sokol (#9413) 2018-08-30 21:32:47 +02:00
secretstore.rs Add type for passwords. (#8920) 2018-06-22 15:09:15 +02:00
signer.rs Remove UI related settings from CLI (#8783) 2018-06-06 10:05:52 +02:00
snapshot.rs db: remove wal disabling / fast-and-loose option. (#8963) 2018-07-10 17:33:25 +02:00
stratum.rs Update license header and scripts (#8666) 2018-06-04 10:19:50 +02:00
upgrade.rs Replace std::env::home_dir() with home crate impl. (#9293) 2018-08-21 15:30:24 +02:00
user_defaults.rs parity: fix UserDefaults json parser (#9189) 2018-07-23 13:57:50 +02:00
whisper.rs Update license header and scripts (#8666) 2018-06-04 10:19:50 +02:00