Skip to content

Conversation

@lafka
Copy link

@lafka lafka commented Oct 3, 2015

Javascript (and therefore MongoDB) has a concept of +-Infinity. This works in other clients bson parsers (at least Haskells) but fails in Erlang (trace below)

Erlang can't process the float that is equivialant of Javascripts Infinity,
Number.(POSITIVE,NEGATIVE)_INFINITY, which is the max- and
minimum floating point.

This patch allows the BSON parser to atleast return something somewhat appropriate.

# try to query back
:poolboy.transaction :mongodb, fn(conn) -> :mongo.find_one(conn, :test, %{}) end
** (exit) exited in: :gen_server.call(#PID<0.3001.0>, {:query, false, false, false, false, :test, 0, -1, %{}, []}, :infinity)
    ** (EXIT) an exception was raised:
        ** (MatchError) no match of right hand side value: <<0, 0, 0, 0, 0, 0, 240, 127>>
            (bson) src/bson_binary.erl:87: :bson_binary.get_field/4
            (bson) src/bson_binary.erl:144: :bson_binary.get_field/2
            (bson) src/bson_binary.erl:54: :bson_binary.get_fields/2
            (bson) src/bson_binary.erl:40: :bson_binary.get_map/1
            (mongodb) src/core/mongo_protocol.erl:111: :mongo_protocol.get_docs/3
            (mongodb) src/core/mongo_protocol.erl:92: :mongo_protocol.get_reply/1
            (mongodb) src/connection/mc_worker_logic.erl:68: :mc_worker_logic.decode_responses/2
            (mongodb) src/connection/mc_worker.erl:102: :mc_worker.handle_info/2

Note on comparison

Since there is no concept of a minimum value both are atoms. This means
you can compare any number to '+infinity" and it will always be larger;
however '-infinity' will also be larger than any number... This means no +infinity > 0 > -infinity.

Erlang can't process the float that is equivialant of Javascripts Infinity
(Number.(POSITIVE,NEGATIVE)_INFINITY) which essentially is the max- and
minimum floating point.

Since there is no concept of a minimum value both are atoms.  This means
you can compare any number to '+infinity" and it will always be larger;
however '-infinity' will also be larger than any number.
@rlipscombe
Copy link

Also NaN. For which there are multiple possible encodings. See my change at rlipscombe@b67b6ae.

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

Successfully merging this pull request may close these issues.

2 participants