Skip to content

32位bug #73

@dimesscn

Description

@dimesscn

Please make sure of the following things.

  • I have read the documentation.
  • 我已阅读 文档
  • I'm sure there are no duplicate issues.
  • 我确定没有提交和他人重复的issue。
  • I'm sure it's due to Spark itself and not my operational issue or something else.
  • 我确定问题由Spark自身引起,不是我自己的操作失误或其他问题。

Version / 版本

0.2.1

Describe the bug / 问题描述

在 device.go 中:
func GetNetIOInfo() (modules.Net, error) {
result := modules.Net{}
first, err := net.IOCounters(false)
if err != nil {
return result, nil
}
if len(first) == 0 {
return result, errors.New(failed to read network io counters)
}
<-time.After(time.Second)
second, err := net.IOCounters(false)
if err != nil {
return result, nil
}
if len(second) == 0 {
return result, errors.New(failed to read network io counters)
}
result.Recv = second[0].BytesRecv - first[0].BytesRecv
result.Sent = second[0].BytesSent - first[0].BytesSent
return result, nil
}
问题所在 :

  • BytesRecv 和 BytesSent 在 i386(32位)架构下,gopsutil 库可能返回 uint32 类型
  • uint32 的最大值是 4,294,967,295 (约 4GB)
  • 当网络流量累积超过 4GB 时,uint32 会溢出,导致数值异常
    正常情况:
    BytesRecv = 4,294,967,295 (uint32 最大值)
    下一次读取时:
    BytesRecv = 0 (溢出后归零)

计算差值:
result.Recv = 0 - 4,294,967,295 = -4,294,967,295
由于 result.Recv 是 uint64 类型,这个负数会被转换为一个巨大的正数(约 18 EB),导致前端显示异常。
overview.jsx 中:
function renderNetworkIO(device) {
let sent = device.net_sent * 8 / 1024;
let recv = device.net_recv * 8 / 1024;
return ${format(sent)} ↑ / ${format(recv)} ↓;

function format(size) {
    if (size <= 1) return '0 Kbps';
    let k = 1024,
        i = Math.floor(Math.log(size) / Math.log(k)),
        units = ['Kbps', 'Mbps', 'Gbps', 'Tbps'];
    return (size / Math.pow(k, i)).toFixed(1) + ' ' + units[i];
}

}
当 device.net_sent 或 device.net_recv 是异常的大数值时, Math.log(size) 会计算出错误的单位索引,导致显示为 TBPS。

Reproduction / 复现方式

amd 9800x3d windows 11 机器测试

Logs / 日志

Additional information / 附加说明

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions