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

Sometimes blocks when launched via NickelMenu #117

Closed
baskerville opened this issue May 24, 2020 · 9 comments
Closed

Sometimes blocks when launched via NickelMenu #117

baskerville opened this issue May 24, 2020 · 9 comments

Comments

@baskerville
Copy link
Owner

I've tried launching Plato via NickelMenu using the following entry:

menu_item  :main  :Start Plato      :cmd_spawn  :quiet:/usr/local/Plato/plato.sh

And it sometimes results in Plato blocking (for a minute or so) on this line! What blocks in load_json is the second line.

@pgaskin
Copy link

pgaskin commented May 25, 2020

Can you try using strace on Plato?

Also, does this also happen if you use cmd_output and & to background Plato?

@baskerville
Copy link
Owner Author

Here's the relevant excerpt from the output of strace:

open("/mnt/onboard/books/.metadata.json", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 5</mnt/onboard/books/.metadata.json> <0.000>
read(5</mnt/onboard/books/.metadata.json>, "{", 1) = 1 <0.000>
getrandom(NULL, 0, GRND_NONBLOCK)       = -1 ENOSYS (Function not implemented) <0.000>
open("/dev/random", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 6</dev/random> <0.000>
ioctl(6</dev/random>, FIOCLEX)          = 0 <0.000>
poll([{fd=6</dev/random>, events=POLLIN}], 1, -1) = 1 ([{fd=6, revents=POLLIN}]) <172.034>
close(6</dev/random>)                   = 0 <0.000>
open("/dev/urandom", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 6</dev/urandom> <0.000>
ioctl(6</dev/urandom>, FIOCLEX)         = 0 <0.000>
read(6</dev/urandom>, "\342\2367\240\370\334D\372\323\306\243\33\324n\312\"p\201Y\206\267\2456i-\314\27D^\1\320r", 32) = 32 <0.000>
read(5</mnt/onboard/books/.metadata.json>, "\n", 1) = 1 <0.000>
read(5</mnt/onboard/books/.metadata.json>, " ", 1) = 1 <0.000>
read(5</mnt/onboard/books/.metadata.json>, " ", 1) = 1 <0.000>
read(5</mnt/onboard/books/.metadata.json>, "\"", 1) = 1 <0.000>
read(5</mnt/onboard/books/.metadata.json>, "5", 1) = 1 <0.000>
read(5</mnt/onboard/books/.metadata.json>, "0", 1) = 1 <0.000>
read(5</mnt/onboard/books/.metadata.json>, "9", 1) = 1 <0.000>

The call that blocks is poll([{fd=6</dev/random>, events=POLLIN}], 1, -1). It seems to be blocking for 172 seconds!

@pgaskin
Copy link

pgaskin commented May 25, 2020

That seems to be blocking due to low entropy before falling back to weaker random numbers. How long have you booted for? Also, can you record the value of /proc/sys/kernel/random/entropy_avail every second or so starting from right after Nickel's launch?

Although, I wonder what's needing truly random numbers in Plato... I suspect it's another thread doing it rather than the JSON parser.

@baskerville
Copy link
Owner Author

Although, I wonder what's needing truly random numbers in Plato... I suspect it's another thread doing it rather than the JSON parser.

I'm afraid it might be the fancy hasher I'm using for the DB's hash map.

@pgaskin
Copy link

pgaskin commented May 25, 2020

So probably shepmaster/twox-hash#13.

@NiLuJe
Copy link
Contributor

NiLuJe commented May 29, 2020

/dev/random is apparently quirky on Kobo, even long after the boot (possibly especially on older devices).

I've had to neuter an OpenSSL feature after a similar issue: koreader/koreader-base#1099

@baskerville
Copy link
Owner Author

I thought it wasn't worth reporting a bug, since the trace is clearly reflecting the behavior of the getrandom crate.

The fact that the function might block is also acknowledged.

I've decided, as consequence, to replace things that might directly or indirectly depend on OsRng, so as to never poll /dev/random.

@NiLuJe
Copy link
Contributor

NiLuJe commented May 30, 2020

Yeah, I'm no expert, but what's surprising is the amount of time it can block, and the fact that it does so long after the early boot.

Might be worse just after a resume from suspend?

@pgaskin
Copy link

pgaskin commented May 30, 2020

Well, on most devices there are more sources of entropy, but the Kobo is pretty bare-bones. And, the lib does use GRND_NONBLOCK (and from a quick look, would fall back to pseudo random numbers afterwards), but that's only supported on 3.14+, so it falls back to a blocking random read.

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

No branches or pull requests

3 participants