go-gomail / gomail

The best way to send emails in Go.
MIT License
4.32k stars 572 forks source link

panic when sending HUGE embedded images #89

Open suntong opened 7 years ago

suntong commented 7 years ago

I'm using gomail to send 15 HUGE images, embedded in the message body, with a total of 60M in size.

This is the first time I'm sending messages of this big, and found that gomail cannot handle it. Here are the errors:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x5a0a20]

goroutine 1 [running]:
github.com/go-gomail/gomail.(*base64LineWriter).Write(0xc420478460, 0xc4200a8038, 0x400, 0x400, 0xc420200000, 0x300, 0x8000)
        /path/to/Go/src/github.com/go-gomail/gomail/writeto.go:292 +0x70
encoding/base64.(*encoder).Write(0xc4200a8000, 0xc420200000, 0x8000, 0x8000, 0x8000, 0x0, 0x0)
        /usr/lib/go-1.8/src/encoding/base64/base64.go:197 +0x2b3
io.copyBuffer(0x7f482d4bc800, 0xc4200a8000, 0x847440, 0xc42000e008, 0xc420200000, 0x8000, 0x8000, 0xc42000e008, 0x0, 0x0)
        /usr/lib/go-1.8/src/io/io.go:392 +0x20b
io.Copy(0x7f482d4bc800, 0xc4200a8000, 0x847440, 0xc42000e008, 0x0, 0x40e2d8, 0x6c0120)
        /usr/lib/go-1.8/src/io/io.go:360 +0x68
github.com/go-gomail/gomail.(*Message).appendFile.func1(0x7f482d4bc800, 0xc4200a8000, 0xc4200a8000, 0x7f482d4bc800)
        /path/to/Go/src/github.com/go-gomail/gomail/message.go:295 +0x7d
github.com/go-gomail/gomail.(*messageWriter).writeBody(0xc4203e73e0, 0xc4200d7fc0, 0x710ef3, 0x6)
        /path/to/Go/src/github.com/go-gomail/gomail/writeto.go:264 +0x29a
github.com/go-gomail/gomail.(*messageWriter).addFiles(0xc4203e73e0, 0xc420096400, 0xf, 0x10, 0x0)
        /path/to/Go/src/github.com/go-gomail/gomail/writeto.go:145 +0x18b
github.com/go-gomail/gomail.(*messageWriter).writeMessage(0xc4203e73e0, 0xc4201fc000)
        /path/to/Go/src/github.com/go-gomail/gomail/writeto.go:48 +0x1c8
github.com/go-gomail/gomail.(*Message).WriteTo(0xc4201fc000, 0x7f482d55a388, 0xc42049a140, 0x7f482d55a388, 0xc42049a140, 0x3)
        /path/to/Go/src/github.com/go-gomail/gomail/writeto.go:17 +0x6d
github.com/go-gomail/gomail.(*smtpSender).Send(0xc420489f00, 0xc42049a040, 0x15, 0xc42048ea50, 0x1, 0x1, 0x846b80, 0xc4201fc000, 0x1, 0x8949e0)
        /path/to/Go/src/github.com/go-gomail/gomail/smtp.go:171 +0x38c
github.com/go-gomail/gomail.send(0x7f482d55a360, 0xc420489f00, 0xc4201fc000, 0x0, 0x70)
        /path/to/Go/src/github.com/go-gomail/gomail/send.go:57 +0xdc
github.com/go-gomail/gomail.Send(0x7f482d55a360, 0xc420489f00, 0xc420101c38, 0x1, 0x1, 0x70, 0x6f4340)
        /path/to/Go/src/github.com/go-gomail/gomail/send.go:38 +0x7a
github.com/go-gomail/gomail.(*Dialer).DialAndSend(0xc4200fabd0, 0xc4201fbc38, 0x1, 0x1, 0x0, 0x0)
        /path/to/Go/src/github.com/go-gomail/gomail/smtp.go:137 +0xe9

The above are from Latest commit (81ebce5 on Apr 11, 2016) https://github.com/go-gomail/gomail/tree/81ebce5c23dfd25c6c67194b37d3dd3f338c98b1, and is triggered from the DialAndSend line of my code, after having done Embed() and NewDialer. The same code works for smaller-size messages. The biggest I've done this far is 10MB.

Will try a 18MB one (in 5 files) and report back -- Yep, works fine. Will try a 30MB one (in 9 files) and report back -- Yep, works fine. Will try a 40MB one and report back -- Yep, works fine. Will try a 50MB one and report back -- Yep, works fine. So, will try again with the 60MB one next Monday and report back.

suntong commented 7 years ago

OK, got the exact error as before when redoing the 60MB one:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x5a0a20]

goroutine 1 [running]:
github.com/go-gomail/gomail.(*base64LineWriter).Write(0xc4203e0080, 0xc4202744b8, 0x400, 0x400, 0xc4200fc000, 0x300, 0x8000)
        /path/to/Go/src/github.com/go-gomail/gomail/writeto.go:292 +0x70
encoding/base64.(*encoder).Write(0xc420274480, 0xc4200fc000, 0x8000, 0x8000, 0x8000, 0x0, 0x0)
        /usr/lib/go-1.8/src/encoding/base64/base64.go:197 +0x2b3
io.copyBuffer(0x7fe934985b98, 0xc420274480, 0x847440, 0xc42012e008, 0xc4200fc000, 0x8000, 0x8000, 0xc42012e008, 0x0, 0x0)
        /usr/lib/go-1.8/src/io/io.go:392 +0x20b
io.Copy(0x7fe934985b98, 0xc420274480, 0x847440, 0xc42012e008, 0x0, 0x40e2d8, 0x6c0120)
        /usr/lib/go-1.8/src/io/io.go:360 +0x68

So,

Confirmed.

Please verify. Thx.

suntong commented 7 years ago

New evidences show that it might not be size related, because

So this is more like a memory related glitch, that might not be that easily to catch. But I do believe that the bigger in size the attainments are, the more likely it will error out.