Fix an use-after-statement-closed error with USING PERIODIC COMMIT
Merge pull request #3706 from jakub-/user-after-statement-closed

Fix an use-after-statement-closed error with USING PERIODIC COMMIT
Merge 2.1-maint in master