Fix race in test
Fix stream state transitions and remove from map when states goes to CLOSED.