Skip to content

Add log to readLoop #641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
## 0.9.3 (May 9, 2024)

### BUG FIXES
* Change filestore.offsets from map[int]msgDef to sync.Map https://github.com/quickfixgo/quickfix/pull/639
* Unregister sessions on stop https://github.com/quickfixgo/quickfix/pull/637
* Corrects ResetOnLogon behavior for initiators https://github.com/quickfixgo/quickfix/pull/635

### FEATURES
* Add AllowUnknownMessageFields & CheckUserDefinedFields settings as included in QuickFIX/J https://github.com/quickfixgo/quickfix/pull/632

## 0.9.2 (April 23, 2024)

### BUG FIXES
* Prevent message queue blocking in the case of network connection trouble https://github.com/quickfixgo/quickfix/pull/615 https://github.com/quickfixgo/quickfix/pull/628
* Corrects validation of multiple repeating groups with different fields https://github.com/quickfixgo/quickfix/pull/623

## 0.9.1 (April 15, 2024)

### BUG FIXES
* Preserve original body when resending https://github.com/quickfixgo/quickfix/pull/624

## 0.9.0 (November 13, 2023)
Expand Down
24 changes: 15 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,30 @@ lint: linters-install
# ---------------------------------------------------------------
# Targets related to running acceptance tests -

ifdef STORE_TYPE
STORE := $(STORE_TYPE)
else
STORE := memory
endif

build-test-srv:
cd _test; go build -o echo_server ./test-server/
cd _test; go build -v -o echo_server ./test-server/
fix40:
cd _test; ./runat.sh $@.cfg 5001 $(STORE_TYPE) "definitions/server/$@/*.def"
cd _test; ./runat.sh $@.cfg 5001 $(STORE) "definitions/server/$@/*.def"
fix41:
cd _test; ./runat.sh $@.cfg 5002 $(STORE_TYPE) "definitions/server/$@/*.def"
cd _test; ./runat.sh $@.cfg 5002 $(STORE) "definitions/server/$@/*.def"
fix42:
cd _test; ./runat.sh $@.cfg 5003 $(STORE_TYPE) "definitions/server/$@/*.def"
cd _test; ./runat.sh $@.cfg 5003 $(STORE) "definitions/server/$@/*.def"
fix43:
cd _test; ./runat.sh $@.cfg 5004 $(STORE_TYPE) "definitions/server/$@/*.def"
cd _test; ./runat.sh $@.cfg 5004 $(STORE) "definitions/server/$@/*.def"
fix44:
cd _test; ./runat.sh $@.cfg 5005 $(STORE_TYPE) "definitions/server/$@/*.def"
cd _test; ./runat.sh $@.cfg 5005 $(STORE) "definitions/server/$@/*.def"
fix50:
cd _test; ./runat.sh $@.cfg 5006 $(STORE_TYPE) "definitions/server/$@/*.def"
cd _test; ./runat.sh $@.cfg 5006 $(STORE) "definitions/server/$@/*.def"
fix50sp1:
cd _test; ./runat.sh $@.cfg 5007 $(STORE_TYPE) "definitions/server/$@/*.def"
cd _test; ./runat.sh $@.cfg 5007 $(STORE) "definitions/server/$@/*.def"
fix50sp2:
cd _test; ./runat.sh $@.cfg 5008 $(STORE_TYPE) "definitions/server/$@/*.def"
cd _test; ./runat.sh $@.cfg 5008 $(STORE) "definitions/server/$@/*.def"

ACCEPT_SUITE=fix40 fix41 fix42 fix43 fix44 fix50 fix50sp1 fix50sp2
accept: $(ACCEPT_SUITE)
Expand Down
9 changes: 8 additions & 1 deletion acceptor.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) quickfixengine.org All rights reserved.

Check failure on line 1 in acceptor.go

View workflow job for this annotation

GitHub Actions / Linter

: # github.com/quickfixgo/quickfix [github.com/quickfixgo/quickfix.test]
//
// This file may be distributed under the terms of the quickfixengine.org
// license as defined by quickfixengine.org and appearing in the file
Expand Down Expand Up @@ -144,6 +144,13 @@
session.stop()
}
a.sessionGroup.Wait()

for sessionID := range a.sessions {
err := UnregisterSession(sessionID)
if err != nil {
return
}
}
}

// RemoteAddr gets remote IP address for a given session.
Expand Down Expand Up @@ -349,7 +356,7 @@

go func() {
msgIn <- fixIn{msgBytes, parser.lastRead}
readLoop(parser, msgIn)
readLoop(parser, msgIn, a.globalLog)
}()

writeLoop(netConn, msgOut, a.globalLog)
Expand Down
2 changes: 2 additions & 0 deletions config/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ const (
MaxLatency string = "MaxLatency"
PersistMessages string = "PersistMessages"
RejectInvalidMessage string = "RejectInvalidMessage"
AllowUnknownMessageFields string = "AllowUnknownMsgFields"
CheckUserDefinedFields string = "ValidateUserDefinedFields"
DynamicSessions string = "DynamicSessions"
DynamicQualifier string = "DynamicQualifier"
)
3 changes: 2 additions & 1 deletion connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ func writeLoop(connection io.Writer, messageOut chan []byte, log Log) {
}
}

func readLoop(parser *parser, msgIn chan fixIn) {
func readLoop(parser *parser, msgIn chan fixIn, log Log) {
defer close(msgIn)

for {
msg, err := parser.ReadMessage()
if err != nil {
log.OnEvent(err.Error())
return
}
msgIn <- fixIn{msg, parser.lastRead}
Expand Down
2 changes: 1 addition & 1 deletion fix_decimal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestFIXDecimalRead(t *testing.T) {
require.Equal(t, test.expectError, err != nil)

if !test.expectError {
assert.True(t, test.expected.Equals(field.Decimal), "Expected %s got %s", test.expected, field.Decimal)
assert.True(t, test.expected.Equal(field.Decimal), "Expected %s got %s", test.expected, field.Decimal)
}
}
}
11 changes: 5 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ module github.com/quickfixgo/quickfix
go 1.21

require (
github.com/armon/go-proxyproto v0.1.0
github.com/mattn/go-sqlite3 v1.14.18
github.com/mattn/go-sqlite3 v1.14.22
github.com/pires/go-proxyproto v0.7.0
github.com/pkg/errors v0.9.1
github.com/shopspring/decimal v1.3.1
github.com/shopspring/decimal v1.4.0
github.com/stretchr/testify v1.8.4
go.mongodb.org/mongo-driver v1.13.0
golang.org/x/net v0.18.0
go.mongodb.org/mongo-driver v1.15.0
golang.org/x/net v0.24.0
)

require (
Expand All @@ -25,7 +24,7 @@ require (
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
golang.org/x/crypto v0.15.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
Expand Down
31 changes: 10 additions & 21 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
github.com/armon/go-proxyproto v0.1.0 h1:TWWcSsjco7o2itn6r25/5AqKBiWmsiuzsUDLT/MTl7k=
github.com/armon/go-proxyproto v0.1.0/go.mod h1:Xj90dce2VKbHzRAeiVQAMBtj4M5oidoXJ8lmgyW21mw=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/klauspost/compress v1.15.12 h1:YClS/PImqYbn+UILDnqxQCZ3RehC9N318SU3kElDUEM=
github.com/klauspost/compress v1.15.12/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
Expand All @@ -18,9 +14,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mattn/go-sqlite3 v1.14.18 h1:JL0eqdCOq6DJVNPSvArO/bIV9/P7fbGrV00LZHc+5aI=
github.com/mattn/go-sqlite3 v1.14.18/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/montanaflynn/stats v0.6.6 h1:Duep6KMIDpY4Yo11iFsvyqJDyfzLF9+sndUKT+v64GQ=
github.com/montanaflynn/stats v0.6.6/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
github.com/pires/go-proxyproto v0.7.0 h1:IukmRewDQFWC7kfnb66CSomk2q/seBuilHBYFwyq0Hs=
Expand All @@ -29,8 +24,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
Expand All @@ -45,45 +40,39 @@ github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4=
github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8=
github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a h1:fZHgsYlfvtyqToslyjUt3VOPF4J7aK/3MPcK7xp3PDk=
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a/go.mod h1:ul22v+Nro/R083muKhosV54bj5niojjWZvU8xrevuH4=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.mongodb.org/mongo-driver v1.13.0 h1:67DgFFjYOCMWdtTEmKFpV3ffWlFnh+CYZ8ZS/tXWUfY=
go.mongodb.org/mongo-driver v1.13.0/go.mod h1:/rGBTebI3XYboVmgz+Wv3Bcbl3aD0QF9zl6kDDw18rQ=
go.mongodb.org/mongo-driver v1.15.0 h1:rJCKC8eEliewXjZGf0ddURtl7tTVy1TK3bfl0gkUSLc=
go.mongodb.org/mongo-driver v1.15.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA=
golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g=
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
10 changes: 9 additions & 1 deletion initiator.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,15 @@ func (i *Initiator) Stop() {
default:
}
close(i.stopChan)

i.wg.Wait()

for sessionID := range i.sessionSettings {
err := UnregisterSession(sessionID)
if err != nil {
return
}
}
}

// NewInitiator creates and initializes a new Initiator.
Expand Down Expand Up @@ -190,7 +198,7 @@ func (i *Initiator) handleConnection(session *session, tlsConfig *tls.Config, di
goto reconnect
}

go readLoop(newParser(bufio.NewReader(netConn)), msgIn)
go readLoop(newParser(bufio.NewReader(netConn)), msgIn, session.log)
disconnected = make(chan interface{})
go func() {
writeLoop(netConn, msgOut, session.log)
Expand Down
3 changes: 1 addition & 2 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,6 @@ func (s *session) prepMessageForSend(msg *Message, inReplyTo *Message) (msgBytes
}

if isAdminMessageType(msgType) {
s.application.ToAdmin(msg, s.sessionID)

if bytes.Equal(msgType, msgTypeLogon) {
var resetSeqNumFlag FIXBoolean
if msg.Body.Has(tagResetSeqNumFlag) {
Expand All @@ -330,6 +328,7 @@ func (s *session) prepMessageForSend(msg *Message, inReplyTo *Message) (msgBytes
msg.Header.SetField(tagMsgSeqNum, FIXInt(seqNum))
}
}
s.application.ToAdmin(msg, s.sessionID)
} else {
if err = s.application.ToApp(msg, s.sessionID); err != nil {
return
Expand Down
12 changes: 12 additions & 0 deletions session_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ func (f sessionFactory) newSession(
}
}

if settings.HasSetting(config.AllowUnknownMessageFields) {
if validatorSettings.AllowUnknownMessageFields, err = settings.BoolSetting(config.AllowUnknownMessageFields); err != nil {
return
}
}

if settings.HasSetting(config.CheckUserDefinedFields) {
if validatorSettings.CheckUserDefinedFields, err = settings.BoolSetting(config.CheckUserDefinedFields); err != nil {
return
}
}

if sessionID.IsFIXT() {
if s.DefaultApplVerID, err = settings.Setting(config.DefaultApplVerID); err != nil {
return
Expand Down
17 changes: 17 additions & 0 deletions session_factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,23 @@ func (s *SessionFactorySuite) TestNewSessionBuildInitiators() {
s.Equal("127.0.0.1:5000", session.SocketConnectAddress[0])
}

func (s *SessionFactorySuite) TestDuplicateSession() {
s.sessionFactory.BuildInitiators = true
s.SessionSettings.Set(config.HeartBtInt, "34")
s.SessionSettings.Set(config.SocketConnectHost, "127.0.0.1")
s.SessionSettings.Set(config.SocketConnectPort, "5000")

session, err := s.createSession(s.SessionID, s.MessageStoreFactory, s.SessionSettings, s.LogFactory, s.App)
s.Nil(err)
s.True(session.InitiateLogon)
_, err = s.createSession(s.SessionID, s.MessageStoreFactory, s.SessionSettings, s.LogFactory, s.App)
s.NotNil(err)
s.Equal("Duplicate SessionID", err.Error())
UnregisterSession(s.SessionID)
_, err = s.createSession(s.SessionID, s.MessageStoreFactory, s.SessionSettings, s.LogFactory, s.App)
s.Nil(err)
}

func (s *SessionFactorySuite) TestNewSessionBuildAcceptors() {
s.sessionFactory.BuildInitiators = false
s.SessionSettings.Set(config.HeartBtInt, "34")
Expand Down
8 changes: 8 additions & 0 deletions session_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ func (sm *stateMachine) Connect(session *session) {
return
}
}

if session.ResetOnLogon {
if err := session.store.Reset(); err != nil {
session.logError(err)
return
}
}

session.log.OnEvent("Sending logon request")
if err := session.sendLogon(); err != nil {
session.logError(err)
Expand Down
10 changes: 7 additions & 3 deletions session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,14 +673,18 @@ func (s *SessionSuite) TestInitiateLogonResetSeqNumFlag() {
}
s.session.State = latentState{}
s.session.HeartBtInt = time.Duration(45) * time.Second
s.Require().Nil(s.store.Reset())
s.NextSenderMsgSeqNum(1)
s.NextTargetMsgSeqNum(1)
s.IncrNextTargetMsgSeqNum()
s.IncrNextSenderMsgSeqNum()
s.session.ResetOnLogon = true
s.session.InitiateLogon = true

s.NextSenderMsgSeqNum(2)
s.NextTargetMsgSeqNum(2)

s.MockApp.On("ToAdmin")
s.MockApp.decorateToAdmin = func(msg *Message) {
msg.Body.SetField(tagResetSeqNumFlag, FIXBoolean(true))
}
s.session.onAdmin(adminMsg)

s.MockApp.AssertExpectations(s.T())
Expand Down
Loading
Loading