Fix for issue #3042: incorrect shutdown in embedded mode

Fix for issue #3042.