Skip to content

fix(auction): place bids atomically to fix concurrent overwrites (#1229) - #1283

Open
saidai-bhuvanesh wants to merge 1 commit into
Nitya-003:mainfrom
saidai-bhuvanesh:fix/issue-1229-atomic-auction-bids
Open

fix(auction): place bids atomically to fix concurrent overwrites (#1229)#1283
saidai-bhuvanesh wants to merge 1 commit into
Nitya-003:mainfrom
saidai-bhuvanesh:fix/issue-1229-atomic-auction-bids

Conversation

@saidai-bhuvanesh

Copy link
Copy Markdown
Contributor

placeBid read auction.currentHighestBid, validated the incoming amount against that stale value, then wrote the new bid later — a non-atomic read-modify-write inside a transaction. Two concurrent bids that both surpassed the same currentHighestBid both passed the lte() guard, both won, and the previous highest bidder was refunded more than once.

Reworks placeBid to use an atomic conditional update (filter on currentHighestBid at write time) so only one concurrent bid can win, and refunds happen exactly once.

Closes #1229

This PR was created by an AI agent (OpenHands) on behalf of saidai-bhuvanesh.

…ya-003#1229)

placeBid used a read-modify-write of the auction document inside a
transaction: findById -> check currentHighestBid -> save. Two
concurrent transactions could both read the same highest bid, both
pass the check, and the second commit silently overwrote the first,
losing a bid and refunding/charging the wrong users.

Replaced with an atomic findOneAndUpdate whose filter enforces
status=active, endTime>now, farmerId!=bidder, and
currentHighestBid<newBid at write time. If no document matches the
bid was overtaken or the auction ended — abort and return an
accurate error. The returned (pre-update) document supplies the real
previous highest bidder for the refund.

Co-authored-by: openhands <openhands@all-hands.dev>
@vercel

vercel Bot commented Aug 8, 2026

Copy link
Copy Markdown

@openhands-agent is attempting to deploy a commit to the Nitya Gosain's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

Place auction bids atomically to fix concurrent overwrites

2 participants