Low level close call that will do correct cleanup and set desired status. Also controls whether user defined callbacks will be triggered. The lock should not be held entering this function. This function will handle the locking manually.
(status Status, doCBs bool, err error)
| 5936 | // will be triggered. The lock should not be held entering this |
| 5937 | // function. This function will handle the locking manually. |
| 5938 | func (nc *Conn) close(status Status, doCBs bool, err error) { |
| 5939 | nc.mu.Lock() |
| 5940 | if nc.isClosed() { |
| 5941 | nc.status = status |
| 5942 | nc.mu.Unlock() |
| 5943 | return |
| 5944 | } |
| 5945 | nc.status = CLOSED |
| 5946 | |
| 5947 | // Kick the Go routines so they fall out. |
| 5948 | nc.kickFlusher() |
| 5949 | |
| 5950 | // If the reconnect timer is waiting between a reconnect attempt, |
| 5951 | // this will kick it out. |
| 5952 | if nc.rqch != nil { |
| 5953 | close(nc.rqch) |
| 5954 | nc.rqch = nil |
| 5955 | } |
| 5956 | |
| 5957 | // Clear any queued pongs, e.g. pending flush calls. |
| 5958 | nc.clearPendingFlushCalls() |
| 5959 | |
| 5960 | // Clear any queued and blocking Requests. |
| 5961 | nc.clearPendingRequestCalls() |
| 5962 | |
| 5963 | // Stop ping timer if set. |
| 5964 | nc.stopPingTimer() |
| 5965 | nc.ptmr = nil |
| 5966 | |
| 5967 | // Need to close and set TCP conn to nil if reconnect loop has stopped, |
| 5968 | // otherwise we would incorrectly invoke Disconnect handler (if set) |
| 5969 | // down below. |
| 5970 | if nc.ar && nc.conn != nil { |
| 5971 | nc.conn.Close() |
| 5972 | nc.conn = nil |
| 5973 | } else if nc.conn != nil { |
| 5974 | // Go ahead and make sure we have flushed the outbound |
| 5975 | nc.bw.flush() |
| 5976 | defer nc.conn.Close() |
| 5977 | } |
| 5978 | |
| 5979 | // Close sync subscriber channels and release any |
| 5980 | // pending NextMsg() calls. |
| 5981 | nc.subsMu.Lock() |
| 5982 | for _, s := range nc.subs { |
| 5983 | s.mu.Lock() |
| 5984 | |
| 5985 | // Release callers on NextMsg for SyncSubscription only |
| 5986 | if s.mch != nil && s.typ == SyncSubscription { |
| 5987 | close(s.mch) |
| 5988 | } |
| 5989 | s.mch = nil |
| 5990 | |
| 5991 | // Call closed handler for non-AsyncSubscription types (AsyncSubscription handlers |
| 5992 | // are called by waitForMsgs when it exits) |
| 5993 | var done func(string) |
| 5994 | if s.typ != AsyncSubscription && s.pDone != nil { |
| 5995 | done = s.pDone |
no test coverage detected