Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
ac5076ce
Commit
ac5076ce
authored
Nov 18, 2023
by
Jeffrey Morgan
Browse files
exponential backoff up to 30s
parent
42c2e3a6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
9 deletions
+10
-9
server/download.go
server/download.go
+4
-7
server/upload.go
server/upload.go
+6
-2
No files found.
server/download.go
View file @
ac5076ce
...
@@ -7,6 +7,7 @@ import (
...
@@ -7,6 +7,7 @@ import (
"fmt"
"fmt"
"io"
"io"
"log"
"log"
"math"
"net/http"
"net/http"
"net/url"
"net/url"
"os"
"os"
...
@@ -147,7 +148,6 @@ func (b *blobDownload) run(ctx context.Context, requestURL *url.URL, opts *Regis
...
@@ -147,7 +148,6 @@ func (b *blobDownload) run(ctx context.Context, requestURL *url.URL, opts *Regis
continue
continue
}
}
i
:=
i
g
.
Go
(
func
()
error
{
g
.
Go
(
func
()
error
{
var
err
error
var
err
error
for
try
:=
0
;
try
<
maxRetries
;
try
++
{
for
try
:=
0
;
try
<
maxRetries
;
try
++
{
...
@@ -158,14 +158,11 @@ func (b *blobDownload) run(ctx context.Context, requestURL *url.URL, opts *Regis
...
@@ -158,14 +158,11 @@ func (b *blobDownload) run(ctx context.Context, requestURL *url.URL, opts *Regis
// return immediately if the context is canceled or the device is out of space
// return immediately if the context is canceled or the device is out of space
return
err
return
err
case
err
!=
nil
:
case
err
!=
nil
:
sleep
:=
200
*
time
.
Millis
econd
+
time
.
Duration
(
try
)
*
time
.
Second
/
4
sleep
:=
time
.
S
econd
*
time
.
Duration
(
math
.
Pow
(
2
,
float64
(
try
)))
log
.
Printf
(
"%s part %d attempt %d failed: %v, retrying in %s"
,
b
.
Digest
[
7
:
19
],
i
,
try
,
err
,
sleep
)
log
.
Printf
(
"%s part %d attempt %d failed: %v, retrying in %s"
,
b
.
Digest
[
7
:
19
],
part
.
N
,
try
,
err
,
sleep
)
time
.
Sleep
(
sleep
)
time
.
Sleep
(
sleep
)
continue
continue
default
:
default
:
if
try
>
0
{
log
.
Printf
(
"%s part %d completed after %d retries"
,
b
.
Digest
[
7
:
19
],
i
,
try
)
}
return
nil
return
nil
}
}
}
}
...
@@ -306,7 +303,7 @@ type downloadOpts struct {
...
@@ -306,7 +303,7 @@ type downloadOpts struct {
fn
func
(
api
.
ProgressResponse
)
fn
func
(
api
.
ProgressResponse
)
}
}
const
maxRetries
=
10
const
maxRetries
=
6
var
errMaxRetriesExceeded
=
errors
.
New
(
"max retries exceeded"
)
var
errMaxRetriesExceeded
=
errors
.
New
(
"max retries exceeded"
)
...
...
server/upload.go
View file @
ac5076ce
...
@@ -8,6 +8,7 @@ import (
...
@@ -8,6 +8,7 @@ import (
"hash"
"hash"
"io"
"io"
"log"
"log"
"math"
"net/http"
"net/http"
"net/url"
"net/url"
"os"
"os"
...
@@ -153,7 +154,7 @@ func (b *blobUpload) Run(ctx context.Context, opts *RegistryOptions) {
...
@@ -153,7 +154,7 @@ func (b *blobUpload) Run(ctx context.Context, opts *RegistryOptions) {
case
errors
.
Is
(
err
,
errMaxRetriesExceeded
)
:
case
errors
.
Is
(
err
,
errMaxRetriesExceeded
)
:
return
err
return
err
case
err
!=
nil
:
case
err
!=
nil
:
sleep
:=
200
*
time
.
Millis
econd
+
time
.
Duration
(
try
)
*
time
.
Second
/
4
sleep
:=
time
.
S
econd
*
time
.
Duration
(
math
.
Pow
(
2
,
float64
(
try
)))
log
.
Printf
(
"%s part %d attempt %d failed: %v, retrying in %s"
,
b
.
Digest
[
7
:
19
],
part
.
N
,
try
,
err
,
sleep
)
log
.
Printf
(
"%s part %d attempt %d failed: %v, retrying in %s"
,
b
.
Digest
[
7
:
19
],
part
.
N
,
try
,
err
,
sleep
)
time
.
Sleep
(
sleep
)
time
.
Sleep
(
sleep
)
continue
continue
...
@@ -244,6 +245,7 @@ func (b *blobUpload) uploadChunk(ctx context.Context, method string, requestURL
...
@@ -244,6 +245,7 @@ func (b *blobUpload) uploadChunk(ctx context.Context, method string, requestURL
return
err
return
err
}
}
// retry uploading to the redirect URL
for
try
:=
0
;
try
<
maxRetries
;
try
++
{
for
try
:=
0
;
try
<
maxRetries
;
try
++
{
err
=
b
.
uploadChunk
(
ctx
,
http
.
MethodPut
,
redirectURL
,
part
,
nil
)
err
=
b
.
uploadChunk
(
ctx
,
http
.
MethodPut
,
redirectURL
,
part
,
nil
)
switch
{
switch
{
...
@@ -252,7 +254,9 @@ func (b *blobUpload) uploadChunk(ctx context.Context, method string, requestURL
...
@@ -252,7 +254,9 @@ func (b *blobUpload) uploadChunk(ctx context.Context, method string, requestURL
case
errors
.
Is
(
err
,
errMaxRetriesExceeded
)
:
case
errors
.
Is
(
err
,
errMaxRetriesExceeded
)
:
return
err
return
err
case
err
!=
nil
:
case
err
!=
nil
:
log
.
Printf
(
"%s part %d attempt %d failed: %v, retrying"
,
b
.
Digest
[
7
:
19
],
part
.
N
,
try
,
err
)
sleep
:=
time
.
Second
*
time
.
Duration
(
math
.
Pow
(
2
,
float64
(
try
)))
log
.
Printf
(
"%s part %d attempt %d failed: %v, retrying in %s"
,
b
.
Digest
[
7
:
19
],
part
.
N
,
try
,
err
,
sleep
)
time
.
Sleep
(
sleep
)
continue
continue
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment