kuzudb / kuzu

Embeddable property graph database management system built for query speed and scalability. Implements Cypher.
https://kuzudb.com/
MIT License
1.27k stars 90 forks source link

Bug: python connection close will crash #3720

Closed min-mwei closed 2 months ago

min-mwei commented 2 months ago

Kùzu version

v0.4.2

What operating system are you using?

Ubuntu 22.04

What happened?

The following code would crash the process when close is called.

import kuzu

db_path='acme'
#db = kuzu.Database(database_path=db_path)
db = kuzu.Database(db_path)
conn = kuzu.Connection(db)
ddl = """
create node table MSEntraRESTCall (objectId string,requestTime timestamp,uri string,uriScheme string,uriHost string,resourcePath string,httpMethod string,respons
eStatusCode int64,ipAddress string,targetObjectIds string,internalCorrelationId string,correlationId string,tenantId string,domainName string,operationName strin
g,appId string,appServicePrincipalId string,resourceAppId string,identityId string,identityType string,selectedProperties string,filteredProperties string,change
dProperties string,uniqueTransactionId string,requestIdFromUti string,primary key(objectId));
"""
ret = conn.execute(ddl)
conn.close()
db.close()

Are there known steps to reproduce?

No response

prrao87 commented 2 months ago

@min-mwei I've seen this same issue come up elsewhere too - may I know the use case for closing the connection explicitly as you did here? The current approach in the Python client is to follow DuckDB's approach, where explicitly closing the connection is not necessary.

mewim commented 2 months ago

I can reproduce this on Ubuntu 22.04 locally. It seems to cause a Segmentation fault. I will look into it.

min-mwei commented 2 months ago

@prrao87 the use case is to run kuzu on the "server side", assume closing the connection is one way to reuse resources especially there are "close API" for both Connection and Database

acquamarin commented 2 months ago

I think the issue is related to the query result deletion. QueryResult is stored in a factorizedTable whose memory is managed by the bufferManager(database component). If we destroy the database before deleting the query result, Segmentation fault. occurs when python deletes the queryResult. The simplest work around is to always delete queryResults before deleting conneciton and database. simply add del ret before the

conn.close()
db.close()

call

mewim commented 2 months ago

I think the issue is related to the query result deletion. QueryResult is stored in a factorizedTable whose memory is managed by the bufferManager(database component). If we destroy the database before deleting the query result, Segmentation fault. occurs when python deletes the queryResult. The simplest work around is to always delete queryResults before deleting conneciton and database. simply add del ret before the

conn.close()
db.close()

call

@min-mwei, we also have a QueryResult.close() method: https://kuzudb.com/api-docs/python/kuzu.html#QueryResult.close

Calling ret.close() before closing the connection and database should fix it. It is a bit safer than deleting ret.