You've already forked pocketbase
							
							
				mirror of
				https://github.com/pocketbase/pocketbase.git
				synced 2025-10-31 16:47:43 +02:00 
			
		
		
		
	added 'table is locked' error msg retry check
This commit is contained in:
		| @@ -46,14 +46,16 @@ func baseLockRetry(op func(attempt int) error, maxRetries int) error { | ||||
| Retry: | ||||
| 	err := op(attempt) | ||||
|  | ||||
| 	if err != nil && | ||||
| 		attempt <= maxRetries && | ||||
| 		// we are checking the plain error text to handle both cgo and noncgo errors | ||||
| 		strings.Contains(err.Error(), "database is locked") { | ||||
| 		// wait and retry | ||||
| 		time.Sleep(getDefaultRetryInterval(attempt)) | ||||
| 		attempt++ | ||||
| 		goto Retry | ||||
| 	if err != nil && attempt <= maxRetries { | ||||
| 		errStr := err.Error() | ||||
| 		// we are checking the error against the plain error texts since the codes could vary between drivers | ||||
| 		if strings.Contains(errStr, "database is locked") || | ||||
| 			strings.Contains(errStr, "table is locked") { | ||||
| 			// wait and retry | ||||
| 			time.Sleep(getDefaultRetryInterval(attempt)) | ||||
| 			attempt++ | ||||
| 			goto Retry | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return err | ||||
|   | ||||
| @@ -33,6 +33,7 @@ func TestBaseLockRetry(t *testing.T) { | ||||
| 		{nil, 3, 1}, | ||||
| 		{errors.New("test"), 3, 1}, | ||||
| 		{errors.New("database is locked"), 3, 3}, | ||||
| 		{errors.New("table is locked"), 3, 3}, | ||||
| 	} | ||||
|  | ||||
| 	for i, s := range scenarios { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user