Skip to content

Commit

Permalink
Limit max send message size to 8192 bytes (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
sitingren authored Jan 21, 2022
1 parent 405d22d commit afb63b2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ['1.16', '1.15', '1.14', '1.13']
go-version: ['1.17', '1.16', '1.15', '1.14', '1.13']

steps:
- name: Check out repository
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ vertica-sql-go is a native Go adapter for the Vertica (http://www.vertica.com) d

Please check out [release notes](https://github.com/vertica/vertica-sql-go/releases) to learn about the latest improvements.

vertica-sql-go has been tested with Vertica 11.0.1 and Go 1.13/1.14/1.15/1.16.
vertica-sql-go has been tested with Vertica 11.0.1 and Go 1.13/1.14/1.15/1.16/1.17.

## Installation

Expand Down
20 changes: 17 additions & 3 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,16 @@ func (v *connection) sendMessageTo(msg msgs.FrontEndMsg, conn net.Conn) error {

_, result = conn.Write(sizeBytes)

if result == nil {
if len(msgBytes) > 0 {
_, result = conn.Write(msgBytes)
if result == nil && len(msgBytes) > 0 {
size := 8192 // Max msg size, consistent with how the server works
pos := 0
var sent int
for pos < len(msgBytes) {
sent, result = conn.Write(msgBytes[pos:min(pos+size, len(msgBytes))])
if result != nil {
break
}
pos += sent
}
}
}
Expand All @@ -371,6 +378,13 @@ func (v *connection) sendMessageTo(msg msgs.FrontEndMsg, conn net.Conn) error {
return result
}

func min(a, b int) int {
if a < b {
return a
}
return b
}

func (v *connection) handshake() error {

if v.connURL.User == nil {
Expand Down

0 comments on commit afb63b2

Please sign in to comment.