Skip to content

Commit

Permalink
SNOW-723750: Panic with readonly file system (#828)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pbulawa committed Jun 23, 2023
1 parent 2b61d99 commit a832856
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
17 changes: 17 additions & 0 deletions file_transfer_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,23 @@ func (sfa *snowflakeFileTransferAgent) uploadFilesParallel(fileMetas []*fileMeta
}
wg.Wait()

// append errors with no result associated to separate array
var errorMessages []string
for i, result := range results {
if result == nil {
if errors[i] == nil {
errorMessages = append(errorMessages, "unknown error")
} else {
errorMessages = append(errorMessages, errors[i].Error())
}
}
}
if errorMessages != nil {
// sort the error messages to be more deterministic as the goroutines may finish in different order each time
sort.Strings(errorMessages)
return fmt.Errorf("errors during file upload:\n%v", strings.Join(errorMessages, "\n"))
}

retryMeta := make([]*fileMetadata, 0)
for i, result := range results {
result.errorDetails = errors[i]
Expand Down
65 changes: 65 additions & 0 deletions file_transfer_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,3 +532,68 @@ func TestUpdateMetadataWithPresignedUrlError(t *testing.T) {
t.Fatalf("unexpected error code. expected: %v, got: %v", ErrCommandNotRecognized, driverErr.Number)
}
}

func TestUploadWhenFilesystemReadOnlyError(t *testing.T) {
// Disable the test on Windows
if isWindows {
return
}

var err error
roPath := t.TempDir()
if err != nil {
t.Fatal(err)
}

// Set the temp directory to read only
err = os.Chmod(roPath, 0444)
if err != nil {
t.Fatal(err)
}

info := execResponseStageInfo{
Location: "gcs-blob/storage/users/456/",
LocationType: "GCS",
}
dir, err := os.Getwd()
if err != nil {
t.Error(err)
}

// Make sure that the test uses read only directory
t.Setenv("TMPDIR", roPath)

uploadMeta := fileMetadata{
name: "data1.txt.gz",
stageLocationType: "GCS",
noSleepingTime: true,
client: gcsClient,
sha256Digest: "123456789abcdef",
stageInfo: &info,
dstFileName: "data1.txt.gz",
srcFileName: path.Join(dir, "/test_data/data1.txt"),
overwrite: true,
options: &SnowflakeFileTransferOptions{
MultiPartThreshold: dataSizeThreshold,
},
}

sfa := &snowflakeFileTransferAgent{
sc: nil,
commandType: uploadCommand,
command: "put file:///tmp/test_data/data1.txt @~",
stageLocationType: gcsClient,
fileMetadata: []*fileMetadata{&uploadMeta},
}

// Set max parallel uploads to 1
sfa.parallel = 1

err = sfa.uploadFilesParallel([]*fileMetadata{&uploadMeta})
if err == nil {
t.Fatal("should error when the filesystem is read only")
}
if !strings.Contains(err.Error(), "errors during file upload:\nmkdir") {
t.Fatalf("should error when creating the temporary directory. Instead errored with: %v", err)
}
}

0 comments on commit a832856

Please sign in to comment.