You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2023/05/15 14:54:02 UTC
[plc4x] branch develop updated: fix(plc4go/spi): fix timing issue when closing cached connection
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/develop by this push:
new c857f837fa fix(plc4go/spi): fix timing issue when closing cached connection
c857f837fa is described below
commit c857f837fa4b00b6b2f1cbcd26f5ddf233521f85
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Mon May 15 16:53:49 2023 +0200
fix(plc4go/spi): fix timing issue when closing cached connection
---
plc4go/pkg/api/cache/plcConnectionLease.go | 17 ++++++---------
plc4go/pkg/api/cache/plcConnectionLease_test.go | 28 +++++++++++++++++++++++++
2 files changed, 34 insertions(+), 11 deletions(-)
diff --git a/plc4go/pkg/api/cache/plcConnectionLease.go b/plc4go/pkg/api/cache/plcConnectionLease.go
index b538b22efa..8ba3a71fda 100644
--- a/plc4go/pkg/api/cache/plcConnectionLease.go
+++ b/plc4go/pkg/api/cache/plcConnectionLease.go
@@ -22,12 +22,12 @@ package cache
import (
"context"
"fmt"
+ "time"
+
plc4go "github.com/apache/plc4x/plc4go/pkg/api"
apiModel "github.com/apache/plc4x/plc4go/pkg/api/model"
"github.com/apache/plc4x/plc4go/spi"
_default "github.com/apache/plc4x/plc4go/spi/default"
- "github.com/apache/plc4x/plc4go/spi/utils"
- "time"
)
type plcConnectionLease struct {
@@ -93,7 +93,7 @@ func (t *plcConnectionLease) Close() <-chan plc4go.PlcConnectionCloseResult {
panic("Called 'Close' on a closed cached connection")
}
- result := make(chan plc4go.PlcConnectionCloseResult)
+ result := make(chan plc4go.PlcConnectionCloseResult, 1)
go func() {
// Check if the connection is still alive, if it is, put it back into the cache
@@ -133,16 +133,11 @@ func (t *plcConnectionLease) Close() <-chan plc4go.PlcConnectionCloseResult {
// Return the connection to the connection container and don't actually close it.
err := t.connectionContainer.returnConnection(newState)
- // Finish closing the connection.
- timeout := time.NewTimer(10 * time.Millisecond)
- defer utils.CleanupTimer(timeout)
- select {
- case result <- _default.NewDefaultPlcConnectionCloseResultWithTraces(t, err, traces):
- case <-timeout.C:
- }
-
// Detach the connection from this lease, so it can no longer be used by the client.
t.connection = nil
+
+ // Finish closing the connection.
+ result <- _default.NewDefaultPlcConnectionCloseResultWithTraces(t, err, traces)
}()
return result
diff --git a/plc4go/pkg/api/cache/plcConnectionLease_test.go b/plc4go/pkg/api/cache/plcConnectionLease_test.go
index e1729045bb..47ee806358 100644
--- a/plc4go/pkg/api/cache/plcConnectionLease_test.go
+++ b/plc4go/pkg/api/cache/plcConnectionLease_test.go
@@ -639,3 +639,31 @@ func TestLeasedPlcConnection_BrowseRequestBuilder(t *testing.T) {
t.Errorf("Timeout")
}
}
+
+func Test_plcConnectionLease_String(t1 *testing.T) {
+ type fields struct {
+ connectionContainer *connectionContainer
+ leaseId uint32
+ connection tracedPlcConnection
+ }
+ tests := []struct {
+ name string
+ fields fields
+ want string
+ }{
+ {
+ name: "String it",
+ want: "plcConnectionLease{connectionContainer: <nil>, leaseId: 0, connection: %!s(<nil>)}",
+ },
+ }
+ for _, tt := range tests {
+ t1.Run(tt.name, func(t1 *testing.T) {
+ t := &plcConnectionLease{
+ connectionContainer: tt.fields.connectionContainer,
+ leaseId: tt.fields.leaseId,
+ connection: tt.fields.connection,
+ }
+ assert.Equalf(t1, tt.want, t.String(), "String()")
+ })
+ }
+}