Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting lots of errors while using tusd with s3 store #1033

Closed
m3rashid opened this issue Nov 21, 2023 · 12 comments
Closed

Getting lots of errors while using tusd with s3 store #1033

m3rashid opened this issue Nov 21, 2023 · 12 comments
Labels

Comments

@m3rashid
Copy link

m3rashid commented Nov 21, 2023

github.com/tus/tusd/v2/pkg/s3store

../../../go/pkg/mod/github.com/tus/tusd/v2@v2.1.0/pkg/s3store/s3store.go:394:18: cannot use int64(len(infoJson)) (value of type int64) as *int64 value in struct literal
../../../go/pkg/mod/github.com/tus/tusd/v2@v2.1.0/pkg/s3store/s3store.go:510:18: cannot use part.number (variable of type int32) as *int32 value in struct literal
../../../go/pkg/mod/github.com/tus/tusd/v2@v2.1.0/pkg/s3store/s3store.go:746:13: cannot use 0 (untyped int constant) as *int32 value in struct literal
../../../go/pkg/mod/github.com/tus/tusd/v2@v2.1.0/pkg/s3store/s3store.go:803:12: cannot use true (untyped bool constant) as *bool value in struct literal
../../../go/pkg/mod/github.com/tus/tusd/v2@v2.1.0/pkg/s3store/s3store.go:845:16: cannot use 1 (untyped int constant) as *int32 value in struct literal
../../../go/pkg/mod/github.com/tus/tusd/v2@v2.1.0/pkg/s3store/s3store.go:869:16: cannot use part.number (variable of type int32) as *int32 value in struct literal
../../../go/pkg/mod/github.com/tus/tusd/v2@v2.1.0/pkg/s3store/s3store.go:995:17: cannot use partNumber (variable of type int32) as *int32 value in struct literal
../../../go/pkg/mod/github.com/tus/tusd/v2@v2.1.0/pkg/s3store/s3store.go:1047:13: cannot use part.PartNumber (variable of type *int32) as int32 value in struct literal
../../../go/pkg/mod/github.com/tus/tusd/v2@v2.1.0/pkg/s3store/s3store.go:1048:13: cannot use part.Size (variable of type *int64) as int64 value in struct literal
../../../go/pkg/mod/github.com/tus/tusd/v2@v2.1.0/pkg/s3store/s3store.go:1053:6: non-boolean condition in if statement
../../../go/pkg/mod/github.com/tus/tusd/v2@v2.1.0/pkg/s3store/s3store.go:1053:6: too many errors

Describe the bug
I just installed the package (go get -u ...) and follow the docs for s3 store on pkg.go.dev

To Reproduce
Steps to reproduce the behavior:

  1. Execute command '...'
  2. Start upload '....'
  3. See error

Expected behavior
A clear and concise description of what you expected to happen.

Setup details
Please provide following details, if applicable to your situation:

  • Operating System: Linux, Ubuntu 22.04 LTS
  • Used tusd version: v2.1.0
  • Used tusd data storage: AWS S3
  • Used tusd configuration: using tusd with programmatic access
  • Used tus client library: No client library(s) used yet, error in starting the server itself
@m3rashid m3rashid added the bug label Nov 21, 2023
@Acconut
Copy link
Member

Acconut commented Nov 21, 2023

It seems you have installed the AWS SDK for Go V1, but tusd uses V2 now (github.com/aws/aws-sdk-go-v2). Please make sure that you provide a V2 instance to s3store. I see that we have an outdated link to V1 on the s3store docs and I will update that one.

Acconut added a commit that referenced this issue Nov 21, 2023
@m3rashid
Copy link
Author

m3rashid commented Nov 22, 2023

@Acconut I am already using the aws-sdk v2, here is my go mod

require (
	github.com/aws/aws-sdk-go-v2/config v1.25.5
	github.com/aws/aws-sdk-go-v2/service/s3 v1.44.0
	github.com/casbin/casbin/v2 v2.77.2
	github.com/casbin/gorm-adapter/v3 v3.20.0
	github.com/go-playground/validator/v10 v10.16.0
	github.com/gofiber/fiber/v2 v2.51.0
	github.com/golang-jwt/jwt/v5 v5.1.0
	github.com/joho/godotenv v1.5.1
	github.com/tus/tusd/v2 v2.1.0
	golang.org/x/crypto v0.15.0
	golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa
	gorm.io/driver/postgres v1.5.4
	gorm.io/gorm v1.25.5
)

@Acconut
Copy link
Member

Acconut commented Nov 22, 2023

How does your code look? Can you provide me with an example to reproduce this?

@m3rashid
Copy link
Author

m3rashid commented Nov 28, 2023

@Acconut Sorry for the late reply, it was a health emergency

// /drive/s3.go
package drive

import (
	"context"
	"log"

	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/aws/aws-sdk-go-v2/service/s3"
)

func s3Client() *s3.Client {
	config, err := config.LoadDefaultConfig(context.TODO())
	if err != nil {
		log.Fatal(err)
	}

	return s3.NewFromConfig(config)
}
// /drive/tus.go
package drive

package drive

import (
	"fmt"
	"os"
	"path/filepath"

	"github.com/gofiber/fiber/v2"
	tusd "github.com/tus/tusd/v2/pkg/handler"
	"github.com/tus/tusd/v2/pkg/s3store"
)

func GetTusHandler(app *fiber.App) *tusd.UnroutedHandler {
	uploadPath, err := filepath.Abs("public/uploads")
	if err != nil {
		panic(fmt.Errorf("unable to get absolute path for uploads directory: %s", err))
	}

	store := s3store.S3Store{
		Bucket:             os.Getenv("AWS_S3_BUCKET_NAME"),
		TemporaryDirectory: uploadPath,
		Service:            s3Client(),
		MaxObjectSize:      500 * 1024 * 1024, // 500MB
	}

	composer := tusd.NewStoreComposer()
	store.UseIn(composer)

	tusdHandler, err := tusd.NewUnroutedHandler(tusd.Config{
		BasePath:              "/api/drive/",
		StoreComposer:         composer,
		NotifyCompleteUploads: true,
	})

	if err != nil {
		panic(fmt.Errorf("unable to create handler: %s", err))
	}

	go func() {
		for {
			event := <-tusdHandler.CompleteUploads
			fmt.Printf("Upload %s finished\n", event.Upload.ID)
		}
	}()

	return tusdHandler
}
// /drive/controller.go
package drive

import (
	"github.com/gofiber/fiber/v2"
	"github.com/gofiber/fiber/v2/middleware/adaptor"
)

func RegisterDriveRoutes(app *fiber.App, checkAuth func() fiber.Handler) *fiber.App {
	tusHandler := GetTusHandler(app)

	app.Post("/api/files/stop", checkAuth(), adaptor.HTTPHandlerFunc(tusHandler.DelFile))
	app.Get("/api/files/download", checkAuth(), adaptor.HTTPHandlerFunc(tusHandler.GetFile))
	app.Head("/api/files/head", checkAuth(), adaptor.HTTPHandlerFunc(tusHandler.HeadFile))
	app.Post("/api/files/patch", checkAuth(), adaptor.HTTPHandlerFunc(tusHandler.PatchFile))
	app.Post("/api/files/upload", checkAuth(), adaptor.HTTPHandlerFunc(tusHandler.PostFile))
	app.Post("/api/files/upload-v2", checkAuth(), adaptor.HTTPHandlerFunc(tusHandler.PostFileV2))

	return app
}
// /main.go
// ...other app configs and routes setups
drive.RegisterDriveRoutes(app, helpers.CheckAuth)
// ... listening for requests to port 4000 (locally, it is not deployed even once yet)

@m3rashid
Copy link
Author

m3rashid commented Nov 28, 2023

There is no problem in the server, the problem occurs when i actually upload the file, (the whole server crashes down)
PS: I am using Uppy with react on the client side

@Acconut
Copy link
Member

Acconut commented Nov 29, 2023

There is no problem in the server, the problem occurs when i actually upload the file, (the whole server crashes down)

I am confused now. In your original statement, you provided errors from build times when the Go code is compiled. But in your latest comment you talk about runtime errors. Can you elaborate what issues you are seeing?

@m3rashid
Copy link
Author

i am seeing issues just when the route is hit.
Maybe I did something to handle at build times. oh yes, i remember. downgraded the tusd version. not using latest now

// go.mod
require (
        // ... other packages
	github.com/aws/aws-sdk-go-v2/config v1.20.0
	github.com/aws/aws-sdk-go-v2/service/s3 v1.41.0
	github.com/gofiber/fiber/v2 v2.51.0
	github.com/tus/tusd/v2 v2.1.0
)
error
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1341c33]

goroutine 26 [running]:
github.com/prometheus/client_golang/prometheus.(*SummaryVec).GetMetricWithLabelValues(0x15?, {0xc000875540?, 0x23a9000?, 0xc000a0bfe8?})
        /home/genos/go/pkg/mod/github.com/prometheus/client_golang@v1.17.0/prometheus/summary.go:611 +0x13
github.com/prometheus/client_golang/prometheus.(*SummaryVec).WithLabelValues(...)
        /home/genos/go/pkg/mod/github.com/prometheus/client_golang@v1.17.0/prometheus/summary.go:644
github.com/tus/tusd/v2/pkg/s3store.S3Store.observeRequestDuration({{0xc0004d5fc3, 0x10}, {0x0, 0x0}, {0x0, 0x0}, {0x182c908, 0xc00050b040}, 0x0, 0x0, ...}, ...)
        /home/genos/go/pkg/mod/github.com/tus/tusd/v2@v2.1.0/pkg/s3store/s3store.go:277 +0xaf
github.com/tus/tusd/v2/pkg/s3store.S3Store.NewUpload({{0xc0004d5fc3, 0x10}, {0x0, 0x0}, {0x0, 0x0}, {0x182c908, 0xc00050b040}, 0x0, 0x0, ...}, ...)
        /home/genos/go/pkg/mod/github.com/tus/tusd/v2@v2.1.0/pkg/s3store/s3store.go:333 +0x57c
github.com/tus/tusd/v2/pkg/handler.(*UnroutedHandler).PostFile(0xc00085bf00, {0x1823a00?, 0xc000910a20?}, 0xc0000bf500)
        /home/genos/go/pkg/mod/github.com/tus/tusd/v2@v2.1.0/pkg/handler/unrouted_handler.go:358 +0x908
net/http.HandlerFunc.ServeHTTP(0xc000888600?, {0x1823a00?, 0xc000910a20?}, 0x23a9000?)
        /usr/local/go/src/net/http/server.go:2136 +0x29
github.com/valyala/fasthttp/fasthttpadaptor.NewFastHTTPHandler.func1(0xc000888600)
        /home/genos/go/pkg/mod/github.com/valyala/fasthttp@v1.51.0/fasthttpadaptor/adaptor.go:58 +0x1e4
github.com/m3rashid/awesome/modules/drive.RegisterDriveRoutes.HTTPHandlerFunc.HTTPHandler.func5(0x13f7a20?)
        /home/genos/go/pkg/mod/github.com/gofiber/fiber/v2@v2.51.0/middleware/adaptor/adaptor.go:26 +0x3e
github.com/gofiber/fiber/v2.(*Ctx).Next(0x227d868?)
        /home/genos/go/pkg/mod/github.com/gofiber/fiber/v2@v2.51.0/ctx.go:1027 +0x3d
github.com/m3rashid/awesome/modules/helpers.CheckAuth.func1(0xc000736c00)
        /home/genos/code/m3rashid/awesome/modules/helpers/auth.go:41 +0x1a5
github.com/gofiber/fiber/v2.(*App).next(0xc000544a00, 0xc000736c00)
        /home/genos/go/pkg/mod/github.com/gofiber/fiber/v2@v2.51.0/router.go:145 +0x1b2
github.com/gofiber/fiber/v2.(*Ctx).Next(0xc000702c90?)
        /home/genos/go/pkg/mod/github.com/gofiber/fiber/v2@v2.51.0/ctx.go:1030 +0x4d
github.com/gofiber/fiber/v2/middleware/logger.New.func3(0xc000736c00)
        /home/genos/go/pkg/mod/github.com/gofiber/fiber/v2@v2.51.0/middleware/logger/logger.go:122 +0x38f
github.com/gofiber/fiber/v2.(*Ctx).Next(0xc0003fc018?)
        /home/genos/go/pkg/mod/github.com/gofiber/fiber/v2@v2.51.0/ctx.go:1027 +0x3d
github.com/gofiber/fiber/v2/middleware/limiter.SlidingWindow.New.func1(0xc000736c00)
        /home/genos/go/pkg/mod/github.com/gofiber/fiber/v2@v2.51.0/middleware/limiter/limiter_sliding.go:115 +0x225
github.com/gofiber/fiber/v2.(*Ctx).Next(0xc000736c00?)
        /home/genos/go/pkg/mod/github.com/gofiber/fiber/v2@v2.51.0/ctx.go:1027 +0x3d
github.com/gofiber/fiber/v2/middleware/favicon.New.func1(0xc000736c00)
        /home/genos/go/pkg/mod/github.com/gofiber/fiber/v2@v2.51.0/middleware/favicon/favicon.go:121 +0xa5
github.com/gofiber/fiber/v2.(*Ctx).Next(0xc000888930?)
        /home/genos/go/pkg/mod/github.com/gofiber/fiber/v2@v2.51.0/ctx.go:1027 +0x3d
github.com/gofiber/fiber/v2/middleware/cors.New.func1(0xc000736c00)
        /home/genos/go/pkg/mod/github.com/gofiber/fiber/v2@v2.51.0/middleware/cors/cors.go:165 +0x3d4
github.com/gofiber/fiber/v2.(*Ctx).Next(0xb?)
        /home/genos/go/pkg/mod/github.com/gofiber/fiber/v2@v2.51.0/ctx.go:1027 +0x3d
main.main.func2(0x1454e40?)
        /home/genos/code/m3rashid/awesome/main.go:57 +0x58
github.com/gofiber/fiber/v2.(*App).next(0xc000544a00, 0xc000736c00)
        /home/genos/go/pkg/mod/github.com/gofiber/fiber/v2@v2.51.0/router.go:145 +0x1b2
github.com/gofiber/fiber/v2.(*App).handler(0xc000544a00, 0x4cf96f?)
        /home/genos/go/pkg/mod/github.com/gofiber/fiber/v2@v2.51.0/router.go:172 +0x78
github.com/valyala/fasthttp.(*Server).serveConn(0xc000624600, {0x182ad48?, 0xc000788010})
        /home/genos/go/pkg/mod/github.com/valyala/fasthttp@v1.51.0/server.go:2359 +0x11d4
github.com/valyala/fasthttp.(*workerPool).workerFunc(0xc0004645a0, 0xc00070c140)
        /home/genos/go/pkg/mod/github.com/valyala/fasthttp@v1.51.0/workerpool.go:224 +0xa4
github.com/valyala/fasthttp.(*workerPool).getCh.func1()
        /home/genos/go/pkg/mod/github.com/valyala/fasthttp@v1.51.0/workerpool.go:196 +0x32
created by github.com/valyala/fasthttp.(*workerPool).getCh in goroutine 1
        /home/genos/go/pkg/mod/github.com/valyala/fasthttp@v1.51.0/workerpool.go:195 +0x1ab

@Acconut
Copy link
Member

Acconut commented Nov 29, 2023

I think you have to use s3store.New to construct the S3Store otherwise you will be missing some of the relevant initialization from

tusd/pkg/s3store/s3store.go

Lines 231 to 245 in 7970961

store := S3Store{
Bucket: bucket,
Service: service,
MaxPartSize: 5 * 1024 * 1024 * 1024,
MinPartSize: 5 * 1024 * 1024,
PreferredPartSize: 50 * 1024 * 1024,
MaxMultipartParts: 10000,
MaxObjectSize: 5 * 1024 * 1024 * 1024 * 1024,
MaxBufferedParts: 20,
TemporaryDirectory: "",
requestDurationMetric: requestDurationMetric,
diskWriteDurationMetric: diskWriteDurationMetric,
uploadSemaphoreDemandMetric: uploadSemaphoreDemandMetric,
uploadSemaphoreLimitMetric: uploadSemaphoreLimitMetric,
}
.

@m3rashid
Copy link
Author

That worked I guess, because I am now getting a new error
Can you please help me on discord or google meet maybe ? Pleasee ....

2023/11/30 14:14:26 ERROR InternalServerError method=POST path=/api/files/upload requestId=3aacc143-1251-467c-8e20-aad14d8ee180 message="s3store: unable to create multipart upload:\nnot found, ResolveEndpointV2"
2023/11/30 14:14:26 INFO ResponseOutgoing method=POST path=/api/files/upload requestId=3aacc143-1251-467c-8e20-aad14d8ee180 status=500 body="ERR_INTERNAL_SERVER_ERROR: s3store: unable to create multipart upload:\nnot found, ResolveEndpointV2\n"
14:14:26 | 500 |     420.799µs |    192.168.1.10 | POST    | /api/files/upload

@Acconut
Copy link
Member

Acconut commented Nov 30, 2023

Two things:

@Acconut
Copy link
Member

Acconut commented Dec 4, 2023

As it turns out, you might be running into issues that are caused by recent breaking changes in the AWS Go SDK. The minor release v1.14.0 of the S3 package introduced a breaking change (https://github.com/aws/aws-sdk-go-v2/blob/release-2023-11-17/feature/s3/manager/CHANGELOG.md#v1140-2023-11-17) to fix issues related to default values (aws/aws-sdk-go-v2#2162). This breaking change seems to be the cause for the compile issues you faced originally.

The runtime error with ResolveEndpointV2 seems to be another breaking change recently in the AWS Go SDK: aws/aws-sdk-go-v2#2370.

I am not sure if and how we can fix them in tusd. Maybe upgrading the AWS SDK version helps, but I am a bit hesitant since this would also be a breaking change for people using tusd as a package.

@Acconut
Copy link
Member

Acconut commented Dec 5, 2023

tusd is now upgraded to the most recent AWS SDK version, so these problems should be fixed in v2.2.0. See #1039 and https://github.com/tus/tusd/releases/tag/v2.2.0 for more details.

@Acconut Acconut closed this as completed Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants