Skip to content

DescriptorTable store descriptors in deterministic order#3614

Merged
sporksmith merged 1 commit intoshadow:mainfrom
sporksmith:sorted-descriptors
Jun 26, 2025
Merged

DescriptorTable store descriptors in deterministic order#3614
sporksmith merged 1 commit intoshadow:mainfrom
sporksmith:sorted-descriptors

Conversation

@sporksmith
Copy link
Copy Markdown
Contributor

@sporksmith sporksmith commented Jun 26, 2025

Previously we were storing them in the HashMap's arbitrary order, and them in that arbitrary order DescriptorTable::remove_all and DescriptorTable::remove_range. Callers of both then close the descriptors and push callbacks in that arbitrary order..

Changing the data structure to BTreeMap ensures we process the descriptors in a deterministic (sorted) order. Alternatively we could just sort the descriptors returned by DescriptorTable::remove_range and DescriptorTable::remov_all, but using a sorted data structure in the first place will make it harder for future subtle bugs of this nature to sneak back in.

This seems to fix some of the nondeterministic scheduling (presumably due to callbacks being called in different order) and nondeterministic file descriptor assignments observed in #3610. Unfortunately not all of it though, and it's difficult to be sure whether it's actually making a difference due to the, err, nondeterministic nondeterminism.

@sporksmith sporksmith requested a review from a team June 26, 2025 02:17
@sporksmith sporksmith self-assigned this Jun 26, 2025
@github-actions github-actions bot added Component: Testing Unit and integration tests and frameworks Component: Main Composing the core Shadow executable labels Jun 26, 2025
@sporksmith sporksmith changed the title DescriptorTable::remove_range: return descriptors in deterministic order DescriptorTable store descriptors in deterministic order Jun 26, 2025
@sporksmith
Copy link
Copy Markdown
Contributor Author

This also affects DescriptorTable::remove_all and its callers; updated description.

Copy link
Copy Markdown
Member

@robgjansen robgjansen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops!

Maybe we should search for other internal uses of HashMap, since it seems to commonly cause determinism problems for us.

@sporksmith
Copy link
Copy Markdown
Contributor Author

Maybe we should search for other internal uses of HashMap, since it seems to commonly cause determinism problems for us.

Yeah, I did that locally to some other ones that looked suspicious, but it didn't seem to help the particular determinism issues I'm running into. Maybe I still ought to clean up and merge them though to eliminate them from future scrutiny/trouble.

Previously we were returning them in the `HashMap`'s arbitrary order,
and then in `SyscallHandler::close_range` closing descriptors and
pushing callbacks in that arbitrary order.

Changing the data structure to `BTreeMap` ensures we process the
descriptors in a deterministic (sorted) order. Alternatively we could
just sort the vector returned by `DescriptorTable::remove_range`, but
using a sorted data structure in the first place will make it harder for
future subtle bugs of this nature to sneak back in.

This seems to fix the nondeterministic scheduling (presumably due to
callbacks being called in different order) and nondeterministic file
descriptor assignments observed in shadow#3610.
@sporksmith sporksmith force-pushed the sorted-descriptors branch from 79df1d4 to e136c92 Compare June 26, 2025 16:24
@sporksmith sporksmith enabled auto-merge June 26, 2025 16:24
@sporksmith sporksmith merged commit 6b72424 into shadow:main Jun 26, 2025
25 checks passed
@sporksmith sporksmith deleted the sorted-descriptors branch June 26, 2025 19:58
sporksmith added a commit to sporksmith/shadow that referenced this pull request Jun 26, 2025
sporksmith added a commit to sporksmith/shadow that referenced this pull request Jun 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: Main Composing the core Shadow executable Component: Testing Unit and integration tests and frameworks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants