def connectionLost(self, reason):
        """
        FIXME: this method is called 4 times on logout....
        it's called once from Avatar.closed() if disconnected
        """
        for i in self.interactors:
            i.sessionClosed()

        if self.stdinlog_open:
            try:
                with open(self.stdinlogFile, 'rb') as f:
                    shasum = hashlib.sha256(f.read()).hexdigest()
                    shasumfile = self.downloadPath + "/" + shasum
                    if (os.path.exists(shasumfile)):
                        os.remove(self.stdinlogFile)
                    else:
                        os.rename(self.stdinlogFile, shasumfile)
                    os.symlink(shasum, self.stdinlogFile)
                log.msg(eventid='cowrie.session.file_download',
                        format='Saved stdin contents to %(outfile)s',
                        url='stdin',
                        outfile=shasumfile,
                        shasum=shasum)
            except IOError as e:
                pass
            finally:
                self.stdinlog_open = False

        if self.ttylog_open:
            # TODO: Add session duration to this entry
            log.msg(eventid='cowrie.log.closed',
                    format='Closing TTY Log: %(ttylog)s after %(duration)d seconds',
                    ttylog=self.ttylogFile,
                    size=self.ttylogSize,
                    duration=self.startTime-time.time())
            ttylog.ttylog_close(self.ttylogFile, time.time())
            self.ttylog_open = False

        insults.ServerProtocol.connectionLost(self, reason)
dataset/ETHPy150Open cowrie/cowrie/cowrie/insults/insults.py/LoggingServerProtocol.connectionLost/swapped operands of `-`