mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-19 17:01:12 +00:00
fix: minio initialization can freeze indefinitely if misconfigured (#8897)
Some checks are pending
/ release (push) Waiting to run
testing-integration / test-sqlite (push) Has been skipped
testing-integration / test-mariadb (v10.6) (push) Has been skipped
testing-integration / test-unit (push) Has been skipped
testing-integration / test-mariadb (v11.8) (push) Has been skipped
testing / backend-checks (push) Has been skipped
testing / frontend-checks (push) Has been skipped
testing / test-unit (push) Has been skipped
testing / test-e2e (push) Has been skipped
testing / test-mysql (push) Has been skipped
testing / test-pgsql (push) Has been skipped
testing / test-sqlite (push) Has been skipped
testing / test-remote-cacher (redis) (push) Has been skipped
testing / test-remote-cacher (valkey) (push) Has been skipped
testing / test-remote-cacher (garnet) (push) Has been skipped
testing / test-remote-cacher (redict) (push) Has been skipped
testing / security-check (push) Has been skipped
Some checks are pending
/ release (push) Waiting to run
testing-integration / test-sqlite (push) Has been skipped
testing-integration / test-mariadb (v10.6) (push) Has been skipped
testing-integration / test-unit (push) Has been skipped
testing-integration / test-mariadb (v11.8) (push) Has been skipped
testing / backend-checks (push) Has been skipped
testing / frontend-checks (push) Has been skipped
testing / test-unit (push) Has been skipped
testing / test-e2e (push) Has been skipped
testing / test-mysql (push) Has been skipped
testing / test-pgsql (push) Has been skipped
testing / test-sqlite (push) Has been skipped
testing / test-remote-cacher (redis) (push) Has been skipped
testing / test-remote-cacher (valkey) (push) Has been skipped
testing / test-remote-cacher (garnet) (push) Has been skipped
testing / test-remote-cacher (redict) (push) Has been skipped
testing / security-check (push) Has been skipped
Fixes #8893 by using a 30 second initialization timeout on the minio storage. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8897 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net> Co-committed-by: Mathieu Fenniak <mathieu@fenniak.net>
This commit is contained in:
parent
3382cd31a9
commit
f9a6657248
2 changed files with 48 additions and 3 deletions
|
@ -9,8 +9,10 @@ import (
|
|||
"net/http/httptest"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"forgejo.org/modules/setting"
|
||||
"forgejo.org/modules/test"
|
||||
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -217,3 +219,41 @@ func TestMinioCredentials(t *testing.T) {
|
|||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestNewMinioStorageInitializationTimeout(t *testing.T) {
|
||||
defer test.MockVariableValue(&getBucketVersioning, func(ctx context.Context, minioClient *minio.Client, bucket string) error {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
case <-time.After(1 * time.Millisecond):
|
||||
return minio.ErrorResponse{
|
||||
StatusCode: http.StatusBadRequest,
|
||||
Code: "TestError",
|
||||
Message: "Mocked error for testing",
|
||||
}
|
||||
}
|
||||
})()
|
||||
|
||||
settings := &setting.Storage{
|
||||
MinioConfig: setting.MinioStorageConfig{
|
||||
Endpoint: "localhost",
|
||||
AccessKeyID: "123456",
|
||||
SecretAccessKey: "12345678",
|
||||
Bucket: "bucket",
|
||||
Location: "us-east-1",
|
||||
},
|
||||
}
|
||||
|
||||
// Verify that we reach `getBucketVersioning` and return the error from our mock.
|
||||
storage, err := NewMinioStorage(t.Context(), settings)
|
||||
require.ErrorContains(t, err, "Mocked error for testing")
|
||||
assert.Nil(t, storage)
|
||||
|
||||
defer test.MockVariableValue(&initializationTimeout, 1*time.Nanosecond)()
|
||||
|
||||
// Now that the timeout is super low, verify that we get a context deadline exceeded error from our mock.
|
||||
storage, err = NewMinioStorage(t.Context(), settings)
|
||||
require.Error(t, err)
|
||||
require.ErrorIs(t, err, context.DeadlineExceeded, "err must be a context deadline exceeded error, but was %v", err)
|
||||
assert.Nil(t, storage)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue