doy57007 2019-05-25 09:40
浏览 38

使用Go Cloud开发套件将exec stdout传递到s3存储桶时,Alrno Linux Docker映像上的Errno 32管道破裂

I wrote a small utility to pipe the output of the mysqldump command to an s3 bucket in golang, which I intend to use to snapshot and restore our database in an end-to-end test environment. When I run this locally, everything works as expected: the utility correctly pipes the mysqldump output to the s3 bucket. However, when running in the Alpine Linux Docker image, I get a broken pipe error. The utility then sends a empty file to the s3 bucket.

To execute mysqldump, I simply use the exec package. Code for mysqldump:

func (conf *MySQLConfig) DumpDatabases(stdout io.Writer) error {
    args := []string{"-u", conf.User, fmt.Sprintf("--password=%s", conf.Password), "-h", conf.Host, "--databases"}
    args = append(args, conf.Databases...)
    cmd := exec.Command("mysqldump", args...)

    cmd.Stdout = stdout
    cmd.Stderr = os.Stderr

    err := cmd.Start()
    if err != nil {
        return err
    }
    cmd.Wait()

    return nil
}

The upload to the S3 bucket utilises the go-cdk. It expects a function that expects an io.Writer as input and returns an error. In this case the following snippet is executed to pipe the output of mysqldump to s3:

bucket.Upload(func(w io.Writer) error { return mysqlConf.DumpDatabases(w) })

Code for the upload:

func (b *Bucket) Upload(writeFunc func(io.Writer) error) error {
    // Open a connection to the bucket.
    ctx := context.Background()

    bucket, err := blob.OpenBucket(ctx, b.Url)

    if err != nil {
        return err
    }
    defer bucket.Close()

    // Add encryption header
    beforeWrite := func(asFunc func(interface{}) bool) error {
        var input *s3manager.UploadInput
        if asFunc(&input) {
            input.ServerSideEncryption = aws.String("AES256")
        }
        return nil
    }

    opts := &blob.WriterOptions{}
    opts.BeforeWrite = beforeWrite

    w, err := bucket.NewWriter(ctx, generateKey(), opts)
    if err != nil {
        return err
    }

    err = writeFunc(w)
    if err != nil {
        return err
    }

    if err := w.Close(); err != nil {
        return err
    }

    return nil
}

Any clue why I get a broken pipe error when running this code on Alpine Linux, while it works as expected locally? Any suggestions on how to debug this issue to figure out what exactly is happening? Should I utilise buffered IO?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
    • ¥15 (标签-MATLAB|关键词-多址)
    • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
    • ¥500 52810做蓝牙接受端
    • ¥15 基于PLC的三轴机械手程序
    • ¥15 多址通信方式的抗噪声性能和系统容量对比
    • ¥15 winform的chart曲线生成时有凸起
    • ¥15 msix packaging tool打包问题
    • ¥15 finalshell节点的搭建代码和那个端口代码教程
    • ¥15 Centos / PETSc / PETGEM