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

[StackerDB] race condition when handling a request for a stale chunk #5067

Open
jcnelson opened this issue Aug 12, 2024 · 0 comments
Open

[StackerDB] race condition when handling a request for a stale chunk #5067

jcnelson opened this issue Aug 12, 2024 · 0 comments

Comments

@jcnelson
Copy link
Member

When handling a request for a chunk that the peer does not have, it performs the following:

let chunk = match stacker_dbs.get_chunk(
    &getchunk.contract_id,
    getchunk.slot_id,
    getchunk.slot_version,
) {
    Ok(Some(chunk)) => chunk,
    Ok(None) => {
        // TODO: this is racey
        if let Ok(Some(actual_version)) =
            stacker_dbs.get_slot_version(&getchunk.contract_id, getchunk.slot_id)
        {
            // request for a stale chunk
            debug!("{:?}: NACK StackerDBGetChunk; version mismatch for requested slot {}.{} for {}. Expected {}", local_peer, getchunk.slot_id, getchunk.slot_version, &getchunk.contract_id, actual_version);
            /* ... etc. */

The call to stacker_dbs.get_chunk(...) and stacker_dbs.get_slot_version(...) need to be transactional, or combined into a single query. A straightforward fix would be to implement a function called get_chunk_or_version(...) which has the same signature as get_chunk(...), but returns the DB's version of the chunk if the given chunk version is not represented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Status: 🆕 New
Development

No branches or pull requests

2 participants