Skylpe 2022-03-25 11:27 采纳率: 0%
浏览 363

关于Flink的The Source Context has been closed already的问题(语言-java)

项目中我要做的是,读取一个bin文件,根据指定协议拆解成数个数组。以下是拆解部分的代码。

 public static void TboxPacketSpliter(FileInputStream inputStream, SourceContext ctx, String vvin, String messageType) throws IOException {
        List<byte[]> byteList = new ArrayList<>();
        byte[] readBuffer = new byte[16];
        boolean ifHead = true;
        //第一条数据单独处理一次
        byte[] supplementBytes = new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00};
        byte[] timestampBytes = new byte[8];
        inputStream.read(timestampBytes);
        byteList.add(supplementBytes);
        byteList.add(timestampBytes);
        while ((inputStream.read(readBuffer) != -1)) {
            for (int i = 0; i < 8; i++) {
                if (readBuffer[i] != (byte) 0x00) {
                    ifHead = false;
                }
            }
            if (ifHead) {
                byte[] outPutBytes = BytesCombine(byteList);
                try {
                    ctx.collect(new Tuple3<>(outPutBytes, messageType, vvin));
                } catch (Exception e) {
                    e.printStackTrace();
                }

                byteList.clear();
                byteList.add(readBuffer);
            } else {
                byteList.add(readBuffer.clone());
                ifHead = true;
            }
        }
        inputStream.close();

    }

org.apache.flink.util.FlinkRuntimeException: The Source Context has been closed already.
    at org.apache.flink.streaming.api.operators.StreamSourceContexts$ClosedContext.throwException(StreamSourceContexts.java:172)
    at org.apache.flink.streaming.api.operators.StreamSourceContexts$ClosedContext.collect(StreamSourceContexts.java:143)
    at org.apache.flink.streaming.api.operators.StreamSourceContexts$SwitchingOnClose.collect(StreamSourceContexts.java:103)
    at com.faw.autopilot.tool_test.TboxTools.TboxPacketSpliter(TboxTools.java:37)
    at com.faw.autopilot.flink_main_test.FlinkSinkTest$SourceFromFile.run(FlinkSinkTest.java:104)
    at org.apache.flink.streaming.api.operators.StreamSource.run(StreamSource.java:116)
    at org.apache.flink.streaming.api.operators.StreamSource.run(StreamSource.java:73)
    at org.apache.flink.streaming.runtime.tasks.SourceStreamTask$LegacySourceFunctionThread.run(SourceStreamTask.java:323)

刚开始运行是没有问题的,当运行一分钟左右之后,对之后的每条数据都会爆出这个错误。问题是我并没有调用过close()方法,让我很迷惑。

希望各位能给予援助,万分感谢!

  • 写回答

1条回答 默认 最新

  • 追风中的小少年 2022-03-25 11:39
    关注

    可能还是flink程序的问题,错误的字面含义貌似是flink停掉了,可以放到环境上的flink里边试试,排查flink的日志信息

    评论

报告相同问题?

问题事件

  • 创建了问题 3月25日

悬赏问题

  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B