Changeset fc8eefcd in mod_gnutls


Ignore:
Timestamp:
Dec 2, 2019, 2:09:59 PM (11 months ago)
Author:
Fiona Klute <fiona.klute@…>
Branches:
master, proxy-ticket
Children:
d9b0936
Parents:
03426e0
git-author:
Fiona Klute <fiona.klute@…> (12/02/19 14:00:48)
git-committer:
Fiona Klute <fiona.klute@…> (12/02/19 14:09:59)
Message:

https-test-client.py: Cleanly shut down the connection subprocess

The call to self.sock.shutdown(socket.SHUT_WR) effectively closes the
subprocess' stdin, telling gnutls-cli to shut down. The wait allows it
and the filter process time to clean up remaining data.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/https-test-client.py

    r03426e0 rfc8eefcd  
    6767            # Critical: "event" is a bitwise OR of the POLL* constants
    6868            for x, event in poller.poll():
    69                 print(f'fd {x}: {event}')
    7069                if event & select.POLLIN or event & select.POLLPRI:
    7170                    data = in_stream.read()
    72                     print(f'read {len(data)} bytes')
    7371                    if cert_log in data:
    7472                        data = data.replace(cert_log, b'')
    75                         print('skip')
    7673                    out_stream.send(data)
    7774                if event & select.POLLHUP or event & select.POLLRDHUP:
     
    7976                    # might be in the list returned by poll() first.
    8077                    run_loop = False
    81                     print('received HUP')
    82                 sys.stdout.flush()
    83 
    84         print('filter process cleanin up')
    85         sys.stdout.flush()
    8678
    8779        in_stream.close()
     
    10294        s_remote.close()
    10395        self.sock = s_local
    104         print(f'socket created {self.sock}')
    105         sys.stdout.flush()
    10696
    10797    def close(self):
    108         traceback.print_stack()
    109         # Wait for the process to stop, send SIGKILL if necessary
    110         self._sproc.terminate()
    111         self.returncode = self._sproc.wait(self.timeout)
    112         if self.returncode == None:
    113             self._sproc.kill()
     98        # close socket to subprocess for writing
     99        if self.sock:
     100            self.sock.shutdown(socket.SHUT_WR)
     101
     102        # Wait for the process to stop, send SIGTERM/SIGKILL if
     103        # necessary
     104        try:
    114105            self.returncode = self._sproc.wait(self.timeout)
    115 
    116         # filter process receives HUP on socket when the subprocess
     106        except subprocess.TimeoutExpired:
     107            try:
     108                self._sproc.terminate()
     109                self.returncode = self._sproc.wait(self.timeout)
     110            except subprocess.TimeoutExpired:
     111                self._sproc.kill()
     112                self.returncode = self._sproc.wait(self.timeout)
     113
     114        # filter process receives HUP on pipe when the subprocess
    117115        # terminates
    118116        self._fproc.join()
    119117
    120         print(f'socket closing {self.sock}')
     118        # close the connection in the super class, which also calls
     119        # self.sock.close()
    121120        super().close()
    122121
Note: See TracChangeset for help on using the changeset viewer.