Don't terminate a context or close a socket more than once