Skip to content

Archiver: fix race condition, dead code path, and remove spin-wait#574

Open
shramanb113 wants to merge 3 commits intointernetarchive:mainfrom
shramanb113:fix/archiver-reliability
Open

Archiver: fix race condition, dead code path, and remove spin-wait#574
shramanb113 wants to merge 3 commits intointernetarchive:mainfrom
shramanb113:fix/archiver-reliability

Conversation

@shramanb113
Copy link
Copy Markdown

Summary

This PR improves the reliability and scalability of the archiver by removing
fragile timing assumptions, eliminating dead code execution, and replacing
a spin-wait in the rate limiter.

Changes

  1. Replaces a time.Sleep used to avoid a known race condition between
    router.Run() and page.Navigate() with a deterministic synchronization
    mechanism.

  2. When asset capture and crawling are disabled, the response body was fully
    discarded but processing continued, leading to MIME detection and buffering
    on an already-consumed stream. An early return is added to avoid unnecessary
    work and ensure correct behavior.

  3. Replaces a busy-wait loop that periodically re-acquired a mutex with a
    time-based wait calculated from the token refill rate.

@yzqzss yzqzss added the AI label Mar 3, 2026
@shramanb113
Copy link
Copy Markdown
Author

Hi @yzqzss ,
I saw that this PR was marked as AI-generated. I want to make it clear that I actually wrote these changes myself. I spent some time debugging. Made these changes by hand. I'm not super familiar with the codebase. I was able to find the issues with the ratelimiter because I've implemented similar things in my own projects.

The other changes I made were just adding comments here and there. I did this because using time.sleep to run the server isn't always the approach.

I promise you I put in effort to make these changes. I think they will make the codebase more robust. If you need information, about how I did it I'd be happy to explain.

@yzqzss yzqzss removed the AI label Mar 5, 2026
Copy link
Copy Markdown
Collaborator

@NGTmeaty NGTmeaty left a comment

Choose a reason for hiding this comment

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

These fixes look good, but I did have one question:

Thanks!

Comment thread pkg/models/item_dedupe.go
if node == nil {
return
}
nodes = append(nodes, node)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This appears to be from your other closed PR. Could we get this removed?

Copy link
Copy Markdown
Collaborator

@yzqzss yzqzss Mar 6, 2026

Choose a reason for hiding this comment

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

re-enter dead lock:

lock() -> unlock() -> lock() -> (continue) -> lock(!)

Copy link
Copy Markdown
Collaborator

@yzqzss yzqzss Mar 6, 2026

Choose a reason for hiding this comment

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

I think this is not the correct fix?

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

Successfully merging this pull request may close these issues.

3 participants