2

I'm using redigo for both regular commands as well as subscribing. Every few days I get this error which causes a panic.

dial tcp IP:6379: connect: connection timed out

I'm guessing there is a some lag or minor disturbance with the network which is causing the connection to time out.

How can I avoid this? I'm OK with the program waiting a few seconds until the problem is resolves, rather than panicking.

How can I avoid this? Should I define Timeouts for Dial? Such as

  • DialReadTimeout
  • DialWriteTimeout
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Rob Fox
  • 5,355
  • 7
  • 37
  • 63

1 Answers1

1

Use DialConnectTimeout to specify a timeout for dialing a network connection or DialNetDial for complete control over dialing a network connection.

The application supplied NetDial function can set timeouts, throttle connect attempts on failure, and more.

Panics related to a dial failure are probably due to a lack of error checking in the application.

DialWriteTimeout and DialReadTimeout are dial options for specifying the timeout when writing a command to the network connection and reading a reply from the network connection respectively. These options have no bearing on timeouts during connect.

Charlie Tumahai
  • 113,709
  • 12
  • 249
  • 242
  • Do you know of a good way to test DialConnectTimeout? Is there a default timeout Redigo will set if DialConnectTimeout is not specified? – Rob Fox Dec 01 '18 at 13:54
  • 1
    Redigo passes the application specified timeout to the network dialer. Redigo does not add any timeouts of its own. Testing that DialConnectTimeout sets [network dial timeout](https://godoc.org/net#Dialer.Timeout) will take some effort, but [the code](https://github.com/gomodule/redigo/blob/bb5990dc771ab24e169aaea90ee3b9ad50cffce9/redis/conn.go#L102-L108) is simple enough that I think you can assume that it works. – Charlie Tumahai Dec 01 '18 at 16:26
  • Thanks a lot! I will further investigate how to trigger some sort of network timeout myself. I'll add my findings here if I do find something. – Rob Fox Dec 02 '18 at 07:10