File tree 1 file changed +9
-2
lines changed
1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -128,6 +128,14 @@ func NewSession(cfg ClusterConfig) (*Session, error) {
128
128
cancel : cancel ,
129
129
}
130
130
131
+ // Close created resources on error otherwise they'll leak
132
+ var err error
133
+ defer func () {
134
+ if err != nil {
135
+ s .Close ()
136
+ }
137
+ }()
138
+
131
139
s .schemaDescriber = newSchemaDescriber (s )
132
140
133
141
s .nodeEvents = newEventDebouncer ("NodeEvents" , s .handleNodeEvent )
@@ -163,8 +171,7 @@ func NewSession(cfg ClusterConfig) (*Session, error) {
163
171
}
164
172
s .connCfg = connCfg
165
173
166
- if err := s .init (); err != nil {
167
- s .Close ()
174
+ if err = s .init (); err != nil {
168
175
if err == ErrNoConnectionsStarted {
169
176
//This error used to be generated inside NewSession & returned directly
170
177
//Forward it on up to be backwards compatible
You can’t perform that action at this time.
0 commit comments