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

:badarith error #18

Closed
OvermindDL1 opened this issue Feb 21, 2017 · 3 comments
Closed

:badarith error #18

OvermindDL1 opened this issue Feb 21, 2017 · 3 comments
Assignees
Labels

Comments

@OvermindDL1
Copy link
Contributor

In the logs I keep getting a :badarith error randomly between 2 to 30 seconds, the stacktrace is (reformatted for readability):

** (ErlangError) erlang error:
[
  reason: :badarith,
  mfa: {Wobserver.Web.Client, :websocket_handle, 3},
  stacktrace: [
    {Wobserver.System.Scheduler, :"-utilization/0-fun-0-", 1, [file: 'lib/wobserver/system/scheduler.ex', line: 37]},
    {Enum, :"-map/2-lists^map/1-0-", 2, [file: 'lib/enum.ex', line: 1229]},
    {Wobserver.System, :overview, 0, [file: 'lib/wobserver/system.ex', line: 54]},
    {Wobserver.Web.Client, :client_handle, 2, [file: 'lib/wobserver/web/client.ex', line: 47]},
    {Wobserver.Web.Client, :websocket_handle, 3, [file: 'lib/wobserver/web/client.ex', line: 5]},
    {:cowboy_websocket, :handler_call, 7, [file: 'c:/Users/<user>/Projects/my_server/deps/cowboy/src/cowboy_websocket.erl', line: 588]},
    {:cowboy_protocol, :execute, 4, [file: 'c:/Users/<user>/Projects/my_server/deps/cowboy/src/cowboy_protocol.erl', line: 442]}
  ],
  msg: {:text, "{\"command\":\"system\",\"data\":null}"},
  req: [
    socket: #Port<0.89433>,
    transport: :ranch_tcp,
    connection: :keepalive,
    pid: #PID<0.1515.0>,
    method: "GET",
    version: :"HTTP/1.1",
    peer: {{10, 1, 2, 158}, 64429},
    host: "<user>",
    host_info: :undefined,
    port: 80,
    path: "/observer/ws",
    path_info: :undefined,
    qs: "",
    qs_vals: :undefined,
    bindings: [],
    headers: [
      {"host", "<user>"},
      {"user-agent", "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0"},
      {"accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"},
      {"accept-language", "en-US,en;q=0.5"}, {"accept-encoding", "gzip, deflate"},
      {"sec-websocket-version", "13"}, {"origin", "http://<user>"},
      {"sec-websocket-extensions", "permessage-deflate"},
      {"sec-websocket-key", "S82iJ2lUI+jBYrl9P6icQQ=="},
      {"cookie", "_my_server_key=snip"},
      {"connection", "keep-alive, Upgrade"},
      {"pragma", "no-cache"},
      {"cache-control", "no-cache"},
      {"upgrade", "websocket"}
    ],
    p_headers: [
      {"sec-websocket-extensions", [{"permessage-deflate", []}]},
      {"upgrade", ["websocket"]},
      {"connection", ["keep-alive", "upgrade"]}
    ],
    cookies: :undefined,
    meta: [websocket_version: 13, websocket_compress: false],
    body_state: :waiting,
    buffer: "",
    multipart: :undefined,
    resp_compress: false,
    resp_state: :done,
    resp_headers: [],
    resp_body: "",
    onresponse: :already_called
  ],
  state: %{proxy: nil, state: %{}}
]
  (cowboy) c:/Users/<user>/Projects/my_server/deps/cowboy/src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4

Specifically it is complaining about the division on line 37 in the lib/wobserver/system/scheduler.ex file, the whole function is:

  def utilization do
    ensure_started()

    case last_utilization() do
      false ->
        get_utilization()
        |> Enum.map(fn {_, u, t} ->u / t end)
      last ->
        get_utilization()
        |> Enum.zip(last)
        |> Enum.map(fn {{_, u0, t0}, {_, u1, t1}} -> (u1 - u0) / (t1 - t0) end)
    end
  end

I also see the error happen on the other Enum.map line as well, specifically it seems t can be 0 in the first Enum.map and t1-t0 can be 0 in the other Enum.map at times, checks probably need to be added to do an alternative action instead.

@IanLuites
Copy link
Contributor

IanLuites commented Feb 21, 2017

Rookie mistake.... I remember thinking: I need to write a 0 check for this.

Will fix.

@IanLuites IanLuites self-assigned this Feb 21, 2017
@IanLuites IanLuites added the bug label Feb 21, 2017
@IanLuites IanLuites added this to the Release v0.1.7 milestone Feb 21, 2017
@OvermindDL1
Copy link
Contributor Author

OvermindDL1 commented Feb 21, 2017

Rookie mistake.... I remember thinking: I need to write a 0 check for this.

Heh, we've all done those plenty. ^.^

IanLuites added a commit that referenced this issue Mar 17, 2017
@IanLuites
Copy link
Contributor

Fixed in release v0.1.7.

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

No branches or pull requests

2 participants