@@ -22,6 +22,7 @@ import (
2222 "github.com/firebirdsql/fbx/fbproto"
2323 "github.com/firebirdsql/fbx/fbproto/auth"
2424 "github.com/firebirdsql/fbx/fbproto/wirecrypt"
25+ "github.com/firebirdsql/fbx/internal/cleanupctx"
2526 "github.com/firebirdsql/fbx/internal/operationerror"
2627)
2728
@@ -1423,7 +1424,7 @@ func (fbConn *FbConn) asyncClose() {
14231424func (fbConn * FbConn ) asyncCloseAfterRead (err error ) {
14241425 var netErr net.Error
14251426 if errors .As (err , & netErr ) && netErr .Timeout () {
1426- fbConn .asyncCloseWithTimeout (cleanupGracePeriod )
1427+ fbConn .asyncCloseWithTimeout (cleanupTimeout () )
14271428 } else {
14281429 fbConn .asyncClose ()
14291430 }
@@ -2867,14 +2868,25 @@ func (rr *ResultReader) SetCallerErr(err error) {
28672868 }
28682869}
28692870
2870- // cleanupGracePeriod bounds cleanup network calls (e.g. op_free_statement) that
2871- // must run even after the caller's ctx has been cancelled.
2872- const cleanupGracePeriod = 5 * time .Second
2871+ // SetCleanupTimeout sets the timeout for the resource cleanup context.
2872+ // The default timeout is 5 seconds.
2873+ // It must be called before using the driver and must not be called
2874+ // concurrently with driver operations.
2875+ // The transmitted timeout must be at least 150 ms.
2876+ func SetCleanupTimeout (timeout time.Duration ) error {
2877+ return cleanupctx .SetCleanupTimeout (timeout )
2878+ }
28732879
2874- // cleanupContext detaches from parent cancellation but preserves Values, with a
2875- // bounded timeout for the network call .
2880+ // cleanupContext returns a context for releasing server-side resources after the
2881+ // user's request has finished .
28762882func cleanupContext (parent context.Context ) (context.Context , context.CancelFunc ) {
2877- return context .WithTimeout (context .WithoutCancel (parent ), cleanupGracePeriod )
2883+ return cleanupctx .CleanupContext (parent )
2884+ }
2885+
2886+ // cleanupTimeout returns a timeout for releasing server-side resources after the
2887+ // user's request has finished.
2888+ func cleanupTimeout () time.Duration {
2889+ return cleanupctx .CleanupTimeout ()
28782890}
28792891
28802892// commitInternalTx rolls back a rejected implicit commit so the next request
@@ -2962,7 +2974,7 @@ func (rr *ResultReader) closeWithoutCommit() (QueryStatus, error) {
29622974 rr .fbConn .contextWatcher .Unwatch ()
29632975 cleanupWatcher := ctxwatch .NewContextWatcher (& DeadlineContextWatcherHandler {
29642976 Conn : rr .fbConn .conn ,
2965- DeadlineDelay : cleanupGracePeriod ,
2977+ DeadlineDelay : cleanupTimeout () ,
29662978 })
29672979 cleanupWatcher .Watch (rr .ctx )
29682980 defer cleanupWatcher .Unwatch ()
@@ -3602,7 +3614,7 @@ func (h *CancelRequestContextWatcherHandler) HandleUnwatchAfterCancel() {
36023614func (h * CancelRequestContextWatcherHandler ) sendCancelOperationWithTimeout (kind int ) error {
36033615 timeout := h .CancelResetTimeout
36043616 if timeout <= 0 {
3605- timeout = 5 * time . Second
3617+ timeout = cleanupTimeout ()
36063618 }
36073619 ctx , cancel := context .WithTimeout (context .Background (), timeout )
36083620 defer cancel ()
0 commit comments