Skip to content

Commit 1da3d19

Browse files
author
Matthew Fisher
committed
fix(logspout): bump packet size to 1048576
By default, linux's socket receivebuffer is set to 256. The kernel doubles this value to allow space for bookkeeping overhead when it is set, therefore our maximum packet size is only 512 bytes. Bumping to a much larger number will prevent an issue like this happening again. Using SetWriteBuffer sets the operating system's transmit buffer associated with this connection, and SetReadBuffer sets the operating system's receive buffer.
1 parent 16c3388 commit 1da3d19

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

logger/syslog/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ func (s *Server) passToHandlers(m SyslogMessage) {
9797
}
9898

9999
func (s *Server) receiver(c net.PacketConn) {
100-
//q := (chan<- Message)(s.q)
101-
buf := make([]byte, 1024)
100+
// make packet buffer the same size as logspout
101+
buf := make([]byte, 1048576)
102102
for {
103103
n, _, err := c.ReadFrom(buf)
104104
if err != nil {

logspout/logspout.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func debug(v ...interface{}) {
2828

2929
func assert(err error, context string) {
3030
if err != nil {
31-
log.Fatal(context+": ", err)
31+
log.Fatalf("%s: %v", context, err)
3232
}
3333
}
3434

@@ -65,6 +65,8 @@ func syslogStreamer(target Target, types []string, logstream chan *Log) {
6565
tag, pid := getLogName(logline.Name)
6666
conn, err := net.Dial("udp", target.Addr)
6767
assert(err, "syslog")
68+
// bump up the packet size for large log lines
69+
assert(conn.SetWriteBuffer(1048576), "syslog")
6870
// HACK: Go's syslog package hardcodes the log format, so let's send our own message
6971
_, err = fmt.Fprintf(conn,
7072
"%s %s[%s]: %s",

tests/apps_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package tests
44

55
import (
6+
"math/rand"
67
"os"
78
"testing"
89

@@ -20,6 +21,15 @@ var (
2021
appsDestroyCmd = "apps:destroy --app={{.AppName}} --confirm={{.AppName}}"
2122
)
2223

24+
func randomString(n int) string {
25+
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
26+
b := make([]rune, n)
27+
for i := range b {
28+
b[i] = letters[rand.Intn(len(letters))]
29+
}
30+
return string(b)
31+
}
32+
2333
func TestApps(t *testing.T) {
2434
params := appsSetup(t)
2535
appsCreateTest(t, params)
@@ -99,6 +109,9 @@ func appsRunTest(t *testing.T, params *utils.DeisTestConfig) {
99109
}
100110
utils.Execute(t, cmd, params, false, "hello")
101111
utils.Execute(t, "apps:run env", params, true, "GIT_SHA")
112+
// run a REALLY large command to test https://github.com/deis/deis/issues/2046
113+
largeString := randomString(1024)
114+
utils.Execute(t, "apps:run echo "+largeString, params, false, largeString)
102115
if err := utils.Chdir(".."); err != nil {
103116
t.Fatal(err)
104117
}

0 commit comments

Comments
 (0)