Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

socket Recv-Q memory leak #828

Open
lgp1122 opened this issue Apr 19, 2024 · 0 comments
Open

socket Recv-Q memory leak #828

lgp1122 opened this issue Apr 19, 2024 · 0 comments

Comments

@lgp1122
Copy link

lgp1122 commented Apr 19, 2024

hello.
I am testing openssl producer with heartbeat on centos7.8 and redhat9.0 x86_64 ,
version of rabbitmq-c is 0.14.0
version of openssl is 1.1.1m
the server is rabbitmq-server (RabbitMQ 3.8.19).
netstat shows the recv queue buffer memory leak.
Proto Recv-Q Send-Q
tcp 846301 0
I find the server send 32 ssize_t data but amqp_ssl_socket_recv only read 8 ssize_t data each heartbeat time.
so I add a loop to read data, it looks like the problem is solved.
but I don't know if it was done the right way or if there are other potential problems.

amqp_openssl.c

static ssize_t amqp_ssl_socket_recv(void *base, void *buf, size_t len,
                                    AMQP_UNUSED int flags) {
  struct amqp_ssl_socket_t *self = (struct amqp_ssl_socket_t *)base;
  int received, tmp_received;
  if (-1 == self->sockfd) {
    return AMQP_STATUS_SOCKET_CLOSED;
  }

  /* SSL_read takes an int for length of buffer, protect against len being
   * larger than larger than what SSL_read can take */
  if (len > INT_MAX) {
    return AMQP_STATUS_INVALID_PARAMETER;
  }

  ERR_clear_error();
  self->internal_error = 0;
  received = 0;
  while (len > received)
  {
    tmp_received = SSL_read(self->ssl, buf + received, (int)(len - received));
    if (tmp_received <= 0) {
      if (0 == received) {
        received = tmp_received;
      }
      break;
    }
    received += tmp_received;
  }
  
  if (0 >= received) {
    self->internal_error = SSL_get_error(self->ssl, received);
    switch (self->internal_error) {
      case SSL_ERROR_WANT_READ:
        received = AMQP_PRIVATE_STATUS_SOCKET_NEEDREAD;
        break;
      case SSL_ERROR_WANT_WRITE:
        received = AMQP_PRIVATE_STATUS_SOCKET_NEEDWRITE;
        break;
      case SSL_ERROR_ZERO_RETURN:
        received = AMQP_STATUS_CONNECTION_CLOSED;
        break;
      default:
        received = AMQP_STATUS_SSL_ERROR;
        break;
    }
  }

  return (ssize_t)received;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant