Skip to content

Commit fe41948

Browse files
committed
Prevent panic on double close
1 parent 82240b4 commit fe41948

3 files changed

Lines changed: 8 additions & 2 deletions

File tree

.github/workflows/tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ jobs:
230230
env:
231231
SODA_DIALECT: "sqlite"
232232
run: |
233+
choco install sqlite
233234
go test -tags sqlite ./...
234235
235236
tests-complete:

connection.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ func (c *Connection) Open() error {
143143

144144
// Close destroys an active datasource connection
145145
func (c *Connection) Close() error {
146+
if c.Store == nil {
147+
return errors.New("connection is not open")
148+
}
146149
if err := c.Store.Close(); err != nil {
147150
return fmt.Errorf("couldn't close connection: %w", err)
148151
}
@@ -297,7 +300,7 @@ func (c *Connection) timeFunc(name string, fn func() error) error {
297300
// Connection type, TX.ID, and optionally a copy ID. It makes it easy to trace
298301
// related queries for a single request.
299302
//
300-
// examples: "conn-7881415437117811350", "tx-4924907692359316530", "tx-831769923571164863-ytzxZa"
303+
// examples: "conn-7881415437117811350", "tx-4924907692359316530", "tx-831769923571164863-ytzxZa"
301304
func (c *Connection) setID(id ...string) {
302305
if len(id) == 1 {
303306
idElems := strings.Split(id[0], "-")

dialect_sqlite_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,15 @@ func TestSqlite_NoDumpSysTables(t *testing.T) {
205205
c, err := NewConnection(cd)
206206
r.NoError(err)
207207
r.NoError(c.Open())
208+
defer c.Close()
208209

209210
r.NoError(c.RawQuery("CREATE TABLE aitest (id integer primary key autoincrement);").Exec())
210211

211-
212212
schema := new(bytes.Buffer)
213213
r.NoError(c.Dialect.DumpSchema(schema))
214214

215215
r.Contains(schema.String(), "CREATE TABLE aitest")
216216
r.NotContains(schema.String(), "CREATE TABLE sqlite_sequence")
217+
218+
r.NoError(c.Close())
217219
}

0 commit comments

Comments
 (0)