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
bf146fb0
Commit
bf146fb0
authored
Sep 07, 2023
by
Michael Yang
Browse files
fix retry on unauthorized chunk
parent
f0f49435
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
18 deletions
+25
-18
server/upload.go
server/upload.go
+25
-18
No files found.
server/upload.go
View file @
bf146fb0
...
...
@@ -66,12 +66,19 @@ func uploadBlobChunked(ctx context.Context, requestURL *url.URL, layer *Layer, r
sectionReader
:=
io
.
NewSectionReader
(
f
,
int64
(
offset
),
chunk
)
for
try
:=
0
;
try
<
MaxRetries
;
try
++
{
ch
:=
make
(
chan
error
,
1
)
r
,
w
:=
io
.
Pipe
()
defer
r
.
Close
()
go
func
()
{
defer
w
.
Close
()
for
chunked
:=
int64
(
0
);
chunked
<
chunk
;
{
select
{
case
err
:=
<-
ch
:
log
.
Printf
(
"chunk interrupted: %v"
,
err
)
return
default
:
n
,
err
:=
io
.
CopyN
(
w
,
sectionReader
,
1024
*
1024
)
if
err
!=
nil
&&
!
errors
.
Is
(
err
,
io
.
EOF
)
{
fn
(
api
.
ProgressResponse
{
...
...
@@ -92,6 +99,7 @@ func uploadBlobChunked(ctx context.Context, requestURL *url.URL, layer *Layer, r
Completed
:
int
(
offset
)
+
int
(
chunked
),
})
}
}
}()
headers
:=
make
(
http
.
Header
)
...
...
@@ -113,6 +121,8 @@ func uploadBlobChunked(ctx context.Context, requestURL *url.URL, layer *Layer, r
switch
{
case
resp
.
StatusCode
==
http
.
StatusUnauthorized
:
ch
<-
errors
.
New
(
"unauthorized"
)
auth
:=
resp
.
Header
.
Get
(
"www-authenticate"
)
authRedir
:=
ParseAuthRedirectString
(
auth
)
token
,
err
:=
getAuthToken
(
ctx
,
authRedir
,
regOpts
)
...
...
@@ -121,10 +131,7 @@ func uploadBlobChunked(ctx context.Context, requestURL *url.URL, layer *Layer, r
}
regOpts
.
Token
=
token
if
_
,
err
:=
sectionReader
.
Seek
(
0
,
io
.
SeekStart
);
err
!=
nil
{
return
err
}
sectionReader
=
io
.
NewSectionReader
(
f
,
int64
(
offset
),
chunk
)
continue
case
resp
.
StatusCode
>=
http
.
StatusBadRequest
:
body
,
_
:=
io
.
ReadAll
(
resp
.
Body
)
...
...
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