Try the SO_LINGER hack to prevent deadlock.