Skip to content
Merged
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
12 changes: 9 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,25 @@ func (c *Client) Connect(ctx context.Context) error {
streamCtx := metadata.AppendToOutgoingContext(context.Background(), "x-api-key", c.key, "x-client-version", Version)
c.txStream, err = c.client.SendTransactionV2(streamCtx)
if err != nil {
c.Close()
if closeErr := c.Close(); closeErr != nil {
c.logger.Warnf("Error closing client during initial txStream setup: %v", closeErr)
}
return err
}

c.txSeqStream, err = c.client.SendTransactionSequenceV2(streamCtx)
if err != nil {
c.Close()
if closeErr := c.Close(); closeErr != nil {
c.logger.Warnf("Error closing client during initial txSeqStream setup: %v", closeErr)
}
return err
}

c.submitBlockStream, err = c.client.SubmitBlockStream(streamCtx)
if err != nil {
c.Close()
if closeErr := c.Close(); closeErr != nil {
c.logger.Warnf("Error closing client during initial submitBlockStream setup: %v", closeErr)
}
return err
}

Expand Down
6 changes: 5 additions & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ func TestConcurrentConnections(t *testing.T) {
defer wg.Done()

client := NewClient(target, apiKey)
defer client.Close()
defer func() {
if err := client.Close(); err != nil {
t.Logf("Client %d failed to close cleanly: %v", clientID, err)
}
}()

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
Expand Down
10 changes: 8 additions & 2 deletions reconnection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ func testReconnection(t *testing.T, target, apiKey string) {

// Create client
fiber := NewClientWithConfig(target, apiKey, config)
defer fiber.Close()
defer func() {
if err := fiber.Close(); err != nil {
t.Logf("Error closing fiber client: %v", err)
}
}()

// Connect to the API
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
Expand Down Expand Up @@ -88,7 +92,9 @@ initialWait:
// Simulate a network interruption by forcibly closing the connection
t.Log("Simulating network interruption...")
disconnectTime := time.Now()
fiber.conn.Close()
if err := fiber.conn.Close(); err != nil {
t.Logf("Error forcibly closing connection: %v", err)
}

// Now wait for transactions to appear after reconnection
t.Log("Waiting for reconnection...")
Expand Down