Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
matrix-media-repo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
matrix-media-repo
Commits
347e74f1
Commit
347e74f1
authored
1 year ago
by
Travis Ralston
Browse files
Options
Downloads
Patches
Plain Diff
Improve error handling around redis cache population on upload
For
https://github.com/turt2live/matrix-media-repo/issues/482
parent
07183614
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pipelines/_steps/upload/redis_async.go
+2
-0
2 additions, 0 deletions
pipelines/_steps/upload/redis_async.go
redislib/cache.go
+17
-5
17 additions, 5 deletions
redislib/cache.go
with
19 additions
and
5 deletions
pipelines/_steps/upload/redis_async.go
+
2
−
0
View file @
347e74f1
...
...
@@ -3,6 +3,7 @@ package upload
import
(
"io"
"github.com/getsentry/sentry-go"
"github.com/turt2live/matrix-media-repo/common/rcontext"
"github.com/turt2live/matrix-media-repo/redislib"
)
...
...
@@ -18,6 +19,7 @@ func PopulateCacheAsync(ctx rcontext.RequestContext, reader io.Reader, size int6
err
=
redislib
.
StoreMedia
(
ctx
,
sha256hash
,
reader
,
size
)
if
err
!=
nil
{
ctx
.
Log
.
Debug
(
"Not populating cache due to error: "
,
err
)
sentry
.
CaptureException
(
err
)
return
}
}()
...
...
This diff is collapsed.
Click to expand it.
redislib/cache.go
+
17
−
5
View file @
347e74f1
...
...
@@ -39,19 +39,31 @@ func StoreMedia(ctx rcontext.RequestContext, hash string, content io.Reader, siz
return
err
}
cleanup
:=
func
()
{
if
delErr
:=
DeleteMedia
(
ctx
,
hash
);
delErr
!=
nil
{
ctx
.
Log
.
Warn
(
"Error while attempting to clean up cache during another error: "
,
delErr
)
sentry
.
CaptureException
(
delErr
)
}
}
buf
:=
make
([]
byte
,
appendBufferSize
)
for
{
read
,
err
:=
content
.
Read
(
buf
)
eof
:=
errors
.
Is
(
err
,
io
.
EOF
)
eof
:=
false
if
err
!=
nil
{
if
errors
.
Is
(
err
,
io
.
EOF
)
{
eof
=
true
}
else
{
cleanup
()
return
err
}
}
if
read
>
0
{
if
err
=
ring
.
ForEachShard
(
ctx
.
Context
,
func
(
ctx2
context
.
Context
,
client
*
redis
.
Client
)
error
{
res
:=
client
.
Append
(
ctx2
,
hash
,
string
(
buf
[
0
:
read
]))
return
res
.
Err
()
});
err
!=
nil
{
if
delErr
:=
DeleteMedia
(
ctx
,
hash
);
delErr
!=
nil
{
ctx
.
Log
.
Warn
(
"Error while attempting to clean up cache during another error: "
,
delErr
)
sentry
.
CaptureException
(
delErr
)
}
cleanup
()
return
err
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment