Close
Closes a BadgerDB database connection and releases all associated resources.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.
Inputs
- Database Id - The unique identifier of the database to close, as returned by the Open node.
How It Works
The Close node properly shuts down a BadgerDB database connection, ensuring all pending writes are flushed to disk and resources are released.
When executed, the node:
- Retrieves the database instance using the provided Database Id
- Closes the database connection gracefully
- Removes the database reference from memory
- Releases all associated resources (file handles, memory buffers, etc.)
Examples
Example 1: Basic Database Lifecycle
Open, use, and close a database:
1. Open
Database Folder: C:\RPA\databases\mydb
Storage: Disk
→ db_id
2. Set (multiple operations...)
Database Id: {{db_id}}
Key: user_count
Value: 100
3. Close
Database Id: {{db_id}}
Example 2: Cleanup in Error Handler
Ensure database is closed even if errors occur:
Try:
1. Open Database
→ db_id
2. Perform Operations...
Database Id: {{db_id}}
Catch:
Log Error
Finally:
Close Database
Database Id: {{db_id}}
Example 3: Multiple Databases
Close multiple database connections:
1. Open (Customer DB) → customer_db_id
2. Open (Product DB) → product_db_id
3. Perform operations...
4. Close Customer DB
Database Id: {{customer_db_id}}
5. Close Product DB
Database Id: {{product_db_id}}
Tips for Effective Use
- Always Close Databases - Use the Close node at the end of your workflow to prevent resource leaks
- Use Finally Blocks - Place Close nodes in finally blocks to ensure cleanup even if errors occur
- Close Before Backup - When backing up an offline database, ensure it's closed first
- Close Inactive Databases - Free resources by closing databases that are no longer needed
- One Close Per Open - Each Open node should have a corresponding Close node
Common Errors and Solutions
Error: "database id cannot be empty"
Solution: Ensure you're passing a valid database ID from the Open node.
Correct:
Open → db_id
Close (Database Id: {{db_id}})
Incorrect:
Close (Database Id: empty or wrong variable)
Error: Database Not Found
Solution: The database may have already been closed or the ID is invalid. Ensure:
- The database was successfully opened before closing
- You're using the correct database ID variable
- The database wasn't already closed earlier in the flow
Resource Still In Use
Solution: Ensure all transactions are committed or discarded before closing:
- Commit all active transactions using Commit Transaction
- Stop all active merge operations using Stop Merge
- Wait for any pending background operations to complete
Best Practices
- Pair Every Open with Close - Maintain a 1:1 relationship between Open and Close nodes
- Use Finally Blocks - Always place Close in a finally block for guaranteed cleanup
- Close in Reverse Order - When using multiple databases, close them in reverse order of opening
- Handle Errors Gracefully - Even if errors occur, ensure Close is called
- Document Lifecycle - Add comments explaining when databases are opened and closed
- Monitor Resources - Close databases promptly to free memory and file handles
Resource Management
When a database is closed:
- All pending writes are flushed to disk
- Memory buffers are released
- File handles are closed
- The database becomes inaccessible for further operations
- Background compaction processes are stopped
Automatic Cleanup
BadgerDB automatically closes all open databases when:
- The automation flow stops
- The OnClose lifecycle event is triggered
- The application shuts down
However, it's still best practice to explicitly close databases for:
- Immediate resource release
- Clear code structure
- Predictable behavior
Related Nodes
- Open - Opens a database connection
- Commit Transaction - Commits pending transaction changes before closing
- Stop Merge - Finalizes merge operations before closing
- Backup - Creates a backup (can be done on open or closed databases)