implement graceful shutdown in native