【问题标题】:the log fd was flush to write to mq socket fd by system系统将日志 fd 刷新写入 mq socket fd
【发布时间】:2023-01-19 00:21:08
【问题描述】:

我使用 python uwsgi 来制作我的代码。当我向 rabbbitmq 发送消息并且没有使用确认模式时,有时会发生错误。错误是这样的:

rabbmitmq 服务器日志错误 =错误报告==== 2022 年 7 月 21 日::15:23:04 === AMQP 连接错误 <0.23590.991>(172.198.12.10:59211 -> 10.0.12.1:5672,虚拟主机:“主机”,用户:“主机”,状态:运行),通道 12848: 无操作导致连接异常 frame_error: "type 91, all octets = <<>>: {frame_too_large,842149168,131064}"

换句话说,我发现我的 python 创建日志文件 fd 也放了一些错误日志:

蟒蛇日志错误 IOError: [Errno 9] 错误的文件描述符 回溯(最后一次通话): 文件“/usr/lib64/python2.6/logging/在里面.py”,第 800 行,在 emit 中 自我冲洗() 文件“/usr/lib64/python2.6/logging/在里面.py”,第 762 行,齐平 self.stream.flush()

这是创建 python 日志文件代码:

   def init_logger(self):
    self._logger = logging.getLogger(self._proj)
    self._logger.setLevel(logging.DEBUG)
    formatter = logging.Formatter('[%(asctime)s] [%(process)d] [%(levelname)s] %(message)s')
    if not self._b_stream_init:
        stream_handler = logging.StreamHandler(sys.stderr)
        stream_handler.setFormatter(formatter)
        stream_handler.setLevel(logging.DEBUG)
        self._logger.addHandler(stream_handler)
        self._b_stream_init = True
    ret = self.check_log_name()
    if ret[0]:
        return 0
    try:
        log_file_handler = logging.FileHandler(ret[1])
        log_file_handler.setFormatter(formatter)
        log_file_handler.setLevel(CLog.LEVEL_MAP[self._log_level])
        self._logger.addHandler(log_file_handler)
        if self._last_file_handle is not None:
            self._logger.removeHandler(self._last_file_handle)
            self._last_file_handle.close()
        self._last_file_handle = log_file_handler
        self._last_log_name = ret[1]
    except:
        pass
def check_log_name(self):
    if self._log_dir is None or self._log_prefix is None:
        return True, None
    log_name_arr = [self._log_dir, self._log_prefix, '_', time.strftime('%Y%m%d_%H'), '.log']
    log_name = ''.join(log_name_arr)
    if self._last_log_name != log_name or not os.path.exists(log_name):
        return False, log_name
    else:
        return True, log_name

此代码引发异常,但我找不到原因。

this code i use client send message to rabbitmq server:
@trace_report(switch=True)
def send(self, key, message, declare=False, expiration=None):

    if declare:
        self._declare_exchange()
        self._declare_queue_with_key(key)
    if isinstance(expiration, int):
        expiration = str(expiration)
    properties = pika.BasicProperties(delivery_mode=2,
                                      expiration=expiration)
    self.channel.basic_publish(exchange=self.exchange, routing_key=key,
                               body=message, properties=properties)

猜测是文件系统误将日志内容写入了rabbitmq server socket fd。在这种情况下我能做什么。

ps:socket_wait 太多(4w)但没有任何内核日志

【问题讨论】:

  • 你没有告诉我们的信息太多了。你是如何创建日志记录的?你在用叉子吗?不知何故,您的日志文件句柄已关闭。这与 rabbitmq 套接字无关。
  • 您可能需要在init_logger 中放置一些调试打印以跟踪发生了什么。不知何故,您的日志文件句柄正在关闭。任何日志消息都有效吗?你知道check_log_name 返回什么吗?
  • 实际上我的 python 代码每小时创建日志 fd,并且在这一点上发生错误。我猜系统将日志内容刷新到 mq 服务器,因此通道关闭。
  • 是的,我必须这样做。在这一点上找不到任何要打印的 python 日志。
  • 请修剪您的代码,以便更容易找到您的问题。按照这些指南创建一个minimal reproducible example

标签: python linux sockets logfile


【解决方案1】:
{frame_too_large,842149168,131064}

意味着您发送的消息大于 RabbitMQ 服务器配置的消息。

您可以尝试增加服务器的最大帧配置,但这也会影响它的性能。

【讨论】:

    猜你喜欢
    • 2017-10-15
    • 1970-01-01
    • 2011-09-21
    • 2021-06-29
    • 2015-08-21
    • 1970-01-01
    • 2013-04-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多