Skip to content

fix: gateway request blocked in store jobs blocking all other requests - #6760

Merged
atzoum merged 2 commits into
masterfrom
fix.txstmtClose
Mar 16, 2026
Merged

atzoum merged 2 commits into
masterfrom
fix.txstmtClose

Conversation

@atzoum

@atzoum atzoum commented Mar 12, 2026 •

Copy link
Copy Markdown
Contributor

🔒 Scanned for secrets using gitleaks 8.30.0

Description

Due to an intermittent network issue, we noticed that although postgres cancelled the COPY command, the client never received the response. This caused the store method to remain blocked indefinitely, which in turn blocked all other requests because of the dsListLock mutex.

To prevent the gateway from being blocked indefinitely, we are adding a watchdog that triggers a panic if the write operation exceeds the 1 minute grace period post the write timeout.

goroutine 6643275 [IO wait, 21 minutes]:
internal/poll.runtime_pollWait(0xffff4dca6a00, 0x72)
	/usr/local/go/src/runtime/netpoll.go:351 +0xa0
internal/poll.(*pollDesc).wait(0x4d4b94b9180?, 0x4d4c297600f?, 0x0)
	/usr/local/go/src/internal/poll/fd_poll_runtime.go:84 +0x28
internal/poll.(*pollDesc).waitRead(...)
	/usr/local/go/src/internal/poll/fd_poll_runtime.go:89
internal/poll.(*FD).Read(0x4d4b94b9180, {0x4d4c297600f, 0x4c4c422e, 0x4c4c422e})
	/usr/local/go/src/internal/poll/fd_unix.go:165 +0x234
net.(*netFD).Read(0x4d4b94b9180, {0x4d4c297600f?, 0x4d50ee3c000?, 0x4d50ee76000?})
	/usr/local/go/src/net/fd_posix.go:68 +0x28
net.(*conn).Read(0x4d4af97e4e0, {0x4d4c297600f?, 0x4d4af580008?, 0x4d4c2976000?})
	/usr/local/go/src/net/net.go:196 +0x34
bufio.(*Reader).Read(0x4d4b9806120, {0x4d4c297600f, 0x4c4c422e, 0x12b17c0?})
	/usr/local/go/src/bufio/bufio.go:231 +0xec
io.ReadAtLeast({0x46a86a0, 0x4d4b9806120}, {0x4d4c2976000, 0x4c4c423d, 0x4c4c423d}, 0x4c4c423d)
	/usr/local/go/src/io/io.go:335 +0x98
io.ReadFull(...)
	/usr/local/go/src/io/io.go:354
github.com/lib/pq.(*conn).recvMessage(0x4d4afe0ca08, 0x4d4b7fa29c0)
	/go/pkg/mod/github.com/lib/[email protected]/conn.go:1075 +0x238
github.com/lib/pq.(*conn).recv1Buf(0x4d4afe0ca08, 0x4d4b7fa29c0)
	/go/pkg/mod/github.com/lib/[email protected]/conn.go:1118 +0x2c
github.com/lib/pq.(*conn).recv1(0x4d4afe0ca08)
	/go/pkg/mod/github.com/lib/[email protected]/conn.go:1145 +0x38
github.com/lib/pq.(*conn).simpleExec(0x4d4afe0ca08, {0x44cbb47, 0x8})
	/go/pkg/mod/github.com/lib/[email protected]/conn.go:582 +0x1d4
github.com/lib/pq.(*conn).rollback(0x4d4afe0ca08)
	/go/pkg/mod/github.com/lib/[email protected]/conn.go:550 +0x3c
github.com/lib/pq.(*conn).Rollback(0x4d4afe0ca08)
	/go/pkg/mod/github.com/lib/[email protected]/conn.go:538 +0x5c
database/sql.(*Tx).rollback.func1()
	/usr/local/go/src/database/sql/sql.go:2345 +0x2c
database/sql.withLock({0x46e3d18, 0x4d4b94b9200}, 0x4d4b9c12f70)
	/usr/local/go/src/database/sql/sql.go:3572 +0x74
database/sql.(*Tx).rollback(0x4d4b07ff400, 0x0)
	/usr/local/go/src/database/sql/sql.go:2344 +0xd8
database/sql.(*Tx).awaitDone(0x4d4b07ff400)
	/usr/local/go/src/database/sql/sql.go:2221 +0x40
created by database/sql.(*DB).beginDC in goroutine 3873565
	/usr/local/go/src/database/sql/sql.go:1925 +0x174


goroutine 3873565 [sync.Mutex.Lock, 21 minutes]:
internal/sync.runtime_SemacquireMutex(0x7a61ba0?, 0xd4?, 0x4d4b006df38?)
	/usr/local/go/src/runtime/sema.go:95 +0x28
internal/sync.(*Mutex).lockSlow(0x4d4b94b9220)
	/usr/local/go/src/internal/sync/mutex.go:149 +0x170
internal/sync.(*Mutex).Lock(...)
	/usr/local/go/src/internal/sync/mutex.go:70
sync.(*Mutex).Lock(...)
	/usr/local/go/src/sync/mutex.go:46
database/sql.(*driverStmt).Close(0x4d4b8698900)
	/usr/local/go/src/database/sql/sql.go:721 +0x34
database/sql.(*Stmt).Close(0x4d4b76d6ab0)
	/usr/local/go/src/database/sql/sql.go:2911 +0x20c
github.com/rudderlabs/rudder-server/jobsdb.(*Handle).doStoreJobsInTx.func1.1()
	/rudder-server/jobsdb/jobsdb.go:2126 +0x20
github.com/rudderlabs/rudder-server/jobsdb.(*Handle).doStoreJobsInTx.func1()
	/rudder-server/jobsdb/jobsdb.go:2134 +0x304
github.com/rudderlabs/rudder-server/jobsdb.(*Handle).doStoreJobsInTx(0x4d4af43ec38?, {0x4714420, 0x4d4bb0bd490}, 0x4d4b7d27b30, {{0x4d4afb7b730, 0xe}, {0x4d4afe1e378, 0x14}, {0x4d4afb7b738, 0x6}}, ...)
	/rudder-server/jobsdb/jobsdb.go:2153 +0xbc
github.com/rudderlabs/rudder-server/jobsdb.(*Handle).internalStoreJobsInTx(0x4d4b0064388, {0x4714420, 0x4d4bb0bd490}, 0x4d4b7d27b30, {{0x4d4afb7b730, 0xe}, {0x4d4afe1e378, 0x14}, {0x4d4afb7b738, 0x6}}, ...)
	/rudder-server/jobsdb/jobsdb.go:1812 +0x314
github.com/rudderlabs/rudder-server/jobsdb.(*Handle).StoreInTx.(*Handle).StoreInTx.func1.func2()
	/rudder-server/jobsdb/jobsdb.go:3237 +0xd4
github.com/rudderlabs/rudder-server/jobsdb.executeDbRequest[...]({0x4714420, 0x4d4bb0bd490}, 0x4d4b0064388, 0x4d4b006e630)
	/rudder-server/jobsdb/queued_db_request.go:46 +0x23c
github.com/rudderlabs/rudder-server/jobsdb.(*Handle).StoreInTx.func1(...)
	/rudder-server/jobsdb/jobsdb.go:3240
github.com/rudderlabs/rudder-server/jobsdb.(*Handle).StoreInTx(0x4d4b0064388, {0x4714420, 0x4d4bb0bd490}, {0x4708140, 0x4d4b9731cf8}, {0x4d4b7d7c908, 0x8b, 0x8b})
	/rudder-server/jobsdb/jobsdb.go:3247 +0x1cc
github.com/rudderlabs/rudder-server/gateway.(*Handle).storeJobs.func1({0x4708140, 0x4d4b9731cf8})
	/rudder-server/gateway/handle.go:1032 +0x68
github.com/rudderlabs/rudder-server/jobsdb.(*Handle).WithStoreSafeTx.func1.1(0x4d4b7d27b30)
	/rudder-server/jobsdb/jobsdb.go:1817 +0x94
github.com/rudderlabs/rudder-server/jobsdb.(*Handle).WithTx(0x4d4afa39140?, {0x4714420, 0x4d4bb0bd490}, 0x4d4b006e940)
	/rudder-server/jobsdb/jobsdb.go:1903 +0x80
github.com/rudderlabs/rudder-server/jobsdb.(*Handle).WithStoreSafeTx.func1()
	/rudder-server/jobsdb/jobsdb.go:1817 +0x38
github.com/rudderlabs/rudder-server/jobsdb.(*Handle).inStoreSafeCtx.func1()
	/rudder-server/jobsdb/jobsdb.go:1834 +0xfc
github.com/rudderlabs/rudder-server/jobsdb.(*Handle).inStoreSafeCtx(0x4d4b0064388, {0x4714420, 0x4d4bb0bd490}, 0x4d4bd10d980?)
	/rudder-server/jobsdb/jobsdb.go:1837 +0x4c
github.com/rudderlabs/rudder-server/jobsdb.(*Handle).WithStoreSafeTx(0x4714378?, {0x4714420?, 0x4d4bb0bd490?}, 0x0?)
	/rudder-server/jobsdb/jobsdb.go:1816 +0x3c
github.com/rudderlabs/rudder-server/gateway.(*Handle).storeJobs(0x4d4af838008, {0x4714378?, 0x4d4bd10d980?}, {0x4d4b7d7c908, 0x8b, 0x8b})
	/rudder-server/gateway/handle.go:1031 +0x10c
github.com/rudderlabs/rudder-server/gateway.(*Handle).StartWebHandler.func4.(*Handle).internalBatchHandler.(*Handle).internalBatchHandlerFunc.13({0x4709870, 0x4d4b9730000}, 0x4d4ba35af00)
	/rudder-server/gateway/handle.go:723 +0x170
github.com/rudderlabs/rudder-server/gateway.(*Handle).StartWebHandler.func4.(*Handle).internalBatchHandler.(*Handle).callType.14({0x4709870, 0x4d4b9730000}, 0x4d4ba35adc0)
	/rudder-server/gateway/handle_http.go:141 +0x84
net/http.HandlerFunc.ServeHTTP(0x3d20c20?, {0x4709870?, 0x4d4b9730000?}, 0x1?)
	/usr/local/go/src/net/http/server.go:2286 +0x38
github.com/go-chi/chi/v5.(*Mux).routeHTTP(0x4d4b0254840, {0x4709870, 0x4d4b9730000}, 0x4d4ba35adc0)
	/go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:479 +0x3b8
net/http.HandlerFunc.ServeHTTP(0x4d4bd10d920?, {0x4709870?, 0x4d4b9730000?}, 0x4d4b006f4f8?)
	/usr/local/go/src/net/http/server.go:2286 +0x38
github.com/go-chi/chi/v5.(*Mux).ServeHTTP(0x4d4b0254840, {0x4709870, 0x4d4b9730000}, 0x4d4ba35adc0)
	/go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:73 +0x2ac
github.com/go-chi/chi/v5.(*Mux).Mount.func1({0x4709870, 0x4d4b9730000}, 0x4d4ba35adc0)
	/go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:321 +0x1b4
net/http.HandlerFunc.ServeHTTP(0x3d20c20?, {0x4709870?, 0x4d4b9730000?}, 0x1?)
	/usr/local/go/src/net/http/server.go:2286 +0x38
github.com/go-chi/chi/v5.(*Mux).routeHTTP(0x4d4b0254060, {0x4709870, 0x4d4b9730000}, 0x4d4ba35adc0)
	/go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:479 +0x3b8
net/http.HandlerFunc.ServeHTTP(0x4d4bd10d890?, {0x4709870?, 0x4d4b9730000?}, 0x14a0000014a?)
	/usr/local/go/src/net/http/server.go:2286 +0x38
github.com/rudderlabs/rudder-server/middleware.init.func1.1({0x4709870, 0x4d4b9730000}, 0x4d4ba35adc0)
	/rudder-server/middleware/uncompress.go:15 +0xc4
net/http.HandlerFunc.ServeHTTP(0x1030006f7b8?, {0x4709870?, 0x4d4b9730000?}, 0x9cb00?)
	/usr/local/go/src/net/http/server.go:2286 +0x38
github.com/rudderlabs/rudder-server/gateway.(*Handle).StartWebHandler.LimitConcurrentRequests.func9.1({0x4709870?, 0x4d4b9730000?}, 0x4d4ba35adc0?)
	/rudder-server/middleware/middleware.go:24 +0xb8
net/http.HandlerFunc.ServeHTTP(0x4d4afe1d008?, {0x4709870?, 0x4d4b9730000?}, 0x95e40?)
	/usr/local/go/src/net/http/server.go:2286 +0x38
github.com/rudderlabs/rudder-go-kit/chiware.StatMiddleware.func3.1({0x4706770, 0x4d4baba0000}, 0x4d4ba35adc0)
	/go/pkg/mod/github.com/rudderlabs/[email protected]/chiware/stats.go:70 +0x130
net/http.HandlerFunc.ServeHTTP(0x4d4afe8c250?, {0x4706770?, 0x4d4baba0000?}, 0x321bc?)
	/usr/local/go/src/net/http/server.go:2286 +0x38
github.com/rudderlabs/rudder-server/gateway.(*Handle).StartWebHandler.func3.1({0x4706770, 0x4d4baba0000}, 0x4d4ba35adc0)
	/rudder-server/gateway/handle_lifecycle.go:569 +0x64
net/http.HandlerFunc.ServeHTTP(0x47143b0?, {0x4706770?, 0x4d4baba0000?}, 0x7a63420?)
	/usr/local/go/src/net/http/server.go:2286 +0x38
github.com/go-chi/chi/v5.(*Mux).ServeHTTP(0x4d4b0254060, {0x4706770, 0x4d4baba0000}, 0x4d4ba35ac80)
	/go/pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:90 +0x26c
github.com/rudderlabs/rudder-server/utils/crash.(*panicLogger).Handler.func1({0x4706770?, 0x4d4baba0000?}, 0x4d4ba35ac80?)
	/rudder-server/utils/crash/logger.go:54 +0x70
net/http.HandlerFunc.ServeHTTP(0x4d4b0208000?, {0x4706770?, 0x4d4baba0000?}, 0x4d4ba35ac80?)
	/usr/local/go/src/net/http/server.go:2286 +0x38
github.com/rudderlabs/rudder-server/gateway.(*Handle).StartWebHandler.(*Cors).Handler.func16({0x4706770, 0x4d4baba0000}, 0x4d4ba35ac80)
	/go/pkg/mod/github.com/rs/[email protected]/cors.go:289 +0x15c
net/http.HandlerFunc.ServeHTTP(0x10?, {0x4706770?, 0x4d4baba0000?}, 0x4d4baba0000?)
	/usr/local/go/src/net/http/server.go:2286 +0x38
net/http.serverHandler.ServeHTTP({0x46dbaa8?}, {0x4706770?, 0x4d4baba0000?}, 0x1?)
	/usr/local/go/src/net/http/server.go:3311 +0xb0
net/http.(*conn).serve(0x4d4b76d6000, {0x4714378, 0x4d4afa91a10})
	/usr/local/go/src/net/http/server.go:2073 +0x51c
created by net/http.(*Server).Serve in goroutine 118
	/usr/local/go/src/net/http/server.go:3464 +0x37c

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

@codecov

codecov Bot commented Mar 12, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.17647% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.76%. Comparing base (5022fbd) to head (7cdbff3).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
gateway/handle.go 90.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6760      +/-   ##
==========================================
- Coverage   80.05%   79.76%   -0.30%     
==========================================
  Files         565      565              
  Lines       63267    63301      +34     
==========================================
- Hits        50651    50494     -157     
- Misses       9631     9829     +198     
+ Partials     2985     2978       -7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@atzoum
atzoum marked this pull request as ready for review March 12, 2026 19:03
@atzoum
atzoum marked this pull request as draft March 12, 2026 19:03
@atzoum atzoum changed the title chore: skip closing statements created by a sql tx fix: gateway request blocked in storeJobs blocking all other requests Mar 12, 2026
@atzoum atzoum changed the title fix: gateway request blocked in storeJobs blocking all other requests fix: gateway request blocked in store jobs blocking all other requests Mar 13, 2026
@atzoum
atzoum removed the request for review from satishrudderstack March 13, 2026 06:14
Base automatically changed from chore.rudoacker to master March 13, 2026 09:01
atzoum added 2 commits March 13, 2026 12:50
🔒 Scanned for secrets using gitleaks 8.30.0
🔒 Scanned for secrets using gitleaks 8.30.0
@atzoum
atzoum marked this pull request as ready for review March 13, 2026 10:51

@mihir20 mihir20 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@atzoum
atzoum merged commit ca4d514 into master Mar 16, 2026
107 of 109 checks passed
@atzoum
atzoum deleted the fix.txstmtClose branch March 16, 2026 07:10
itsmihir pushed a commit that referenced this pull request Mar 16, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.70.0-rc.1](v1.69.0...v1.70.0-rc.1)
(2026-03-16)


### Features

* add a scheduled release cut workflow to cut release branches
([#6739](#6739))
([ab887ac](ab887ac))
* infer OAuth type from account definition when destination supports
accounts
([#6718](#6718))
([00d1755](00d1755))


### Bug Fixes

* false sanity check failure due to empty response
([#6762](#6762))
([0384603](0384603))
* gateway request blocked in store jobs blocking all other requests
([#6760](#6760))
([ca4d514](ca4d514))
* respect context cancellation in gateway rate limiter
([#6751](#6751))
([589251a](589251a))
* update prerelease branch versioning format in scheduled release
workflow
([#6745](#6745))
([fede9e4](fede9e4))


### Miscellaneous

* add check for pseudo-version dependencies in rudderlabs modules
([#6737](#6737))
([55ecd10](55ecd10))
* bump rudder-go-kit to 0.73.0
([#6753](#6753))
([1743f6b](1743f6b))
* remove gunicorn and add darwin compatibility
([#6742](#6742))
([392d1f4](392d1f4))
* use latest retryablehttp client
([#6754](#6754))
([629f036](629f036))
* user rudo docker image for partition migration integration tests
([#6757](#6757))
([5022fbd](5022fbd))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
itsmihir pushed a commit that referenced this pull request Mar 17, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.70.0](v1.69.0...v1.70.0)
(2026-03-16)


### Features

* add a scheduled release cut workflow to cut release branches
([#6739](#6739))
([ab887ac](ab887ac))
* infer OAuth type from account definition when destination supports
accounts
([#6718](#6718))
([00d1755](00d1755))


### Bug Fixes

* false sanity check failure due to empty response
([#6762](#6762))
([0384603](0384603))
* gateway request blocked in store jobs blocking all other requests
([#6760](#6760))
([ca4d514](ca4d514))
* respect context cancellation in gateway rate limiter
([#6751](#6751))
([589251a](589251a))
* update prerelease branch versioning format in scheduled release
workflow
([#6745](#6745))
([fede9e4](fede9e4))


### Miscellaneous

* add check for pseudo-version dependencies in rudderlabs modules
([#6737](#6737))
([55ecd10](55ecd10))
* bump rudder-go-kit to 0.73.0
([#6753](#6753))
([1743f6b](1743f6b))
* remove gunicorn and add darwin compatibility
([#6742](#6742))
([392d1f4](392d1f4))
* use latest retryablehttp client
([#6754](#6754))
([629f036](629f036))
* user rudo docker image for partition migration integration tests
([#6757](#6757))
([5022fbd](5022fbd))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
atzoum added a commit that referenced this pull request Nov 6, 2026
#7578)

# Description

Cancelling a transaction's context while a COPY is open makes
`database/sql` send `ROLLBACK` while lib/pq's COPY response reader is
still reading the connection. One of the two then waits forever for a
reply the other consumed, holding the connection lock, so the store
never returns; in the partition migration server this also blocks gRPC
shutdown.

This is probably also what caused the gateway hangs behind #6760:
`storeJobs` cancels its transaction at `WriteTimeout`, and the stacks in
that PR show the same deadlock, with `Tx.awaitDone` stuck in `Rollback`
and `doStoreJobsInTx` waiting on `Stmt.Close`. The
`startStoreJobsWatchdog` added there stays in place.

Points `lib/pq` at `rudderlabs/pq`, v1.12.3 plus a fix that ends the
COPY before `ROLLBACK`/`COMMIT`. The `replace` goes away once
lib/pq#1452 is fixed in a release.

## Linear Ticket

n/a

## Security

- [x] The code changed/added as part of this pull request won't create
any security issues with how the software is being used.
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.

4 participants