Just for completeness based on our discussion...

Add a helper function for cleaning up the port. It should obtain the pid of the port process using port_info, close the port, use os:cmd to kill -9 the pid.

The helper function should get called in terminate.

The helper function should get called if port returns timeout or if our receive here hits the timeout.