Issue #489

Check transport before closing. It may not be set if a disconnect occurs before a handshake is completed. Issue #489.