diff --git a/package.json b/package.json index d371b6a..e9a75ce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cosmos-server", - "version": "0.12.0-unstable44", + "version": "0.12.0-unstable45", "description": "", "main": "test-server.js", "bugs": { diff --git a/src/utils/db.go b/src/utils/db.go index 22bee9e..4ab9e12 100644 --- a/src/utils/db.go +++ b/src/utils/db.go @@ -107,6 +107,7 @@ func InitDBBuffers() { func flushBuffer(collectionName string) { bufferLock.Lock() + defer bufferLock.Unlock() objects, exists := writeBuffer[collectionName] if exists && len(objects) > 0 { collection, errG := GetCollection(GetRootAppId(), collectionName) @@ -119,11 +120,11 @@ func flushBuffer(collectionName string) { } writeBuffer[collectionName] = make([]map[string]interface{}, 0) } - bufferLock.Unlock() } func flushAllBuffers() { bufferLock.Lock() + defer bufferLock.Unlock() for collectionName, objects := range writeBuffer { if len(objects) > 0 { collection, errG := GetCollection(GetRootAppId(), collectionName) @@ -137,7 +138,6 @@ func flushAllBuffers() { writeBuffer[collectionName] = make([]map[string]interface{}, 0) } } - bufferLock.Unlock() } func BufferedDBWrite(collectionName string, object map[string]interface{}) { @@ -147,6 +147,8 @@ func BufferedDBWrite(collectionName string, object map[string]interface{}) { if len(writeBuffer[collectionName]) >= bufferCapacity { bufferLock.Unlock() flushBuffer(collectionName) + } else { + bufferLock.Unlock() } }