Skip to content

bson module not thread safe (using globals) #11

@UNIcodeX

Description

@UNIcodeX

Would you mind making the bson module thread safe? Or if you'll give me some direction, I can work on it and submit a PR.

test code

import threadpool
import jester
import json
import mongopool
import bson

connectMongoPool("mongodb://User:Pass@localhost:27017/DB?authSource=admin")

var
  db {.threadvar.}: MongoConnection 

proc getDB(): MongoConnection =
  db = getNextConnection()
  return db

settings:
  port = Port(8000)
  staticDir = "static"

routes:
  get "/getCollection":
    var
      db = getDB()
      docs = db.find("collection", @@{"active": true}).returnMany()
      sRes: seq[JsonNode]
    for doc in docs:
      sRes.add(parseJson(doc.pretty))
    releaseConnection(db)
    resp %*sRes

releaseConnection(db)

The error

#[
/home/j/.nimble/pkgs/jester-0.4.3/jester.nim(1277, 9) Hint: Asynchronous route: match. [User]
/home/j/nm.nim(26, 1) template/generic instantiation of `routes` from here
/home/j/.nimble/pkgs/jester-0.4.3/jester.nim(1283, 35) template/generic instantiation of `async` from here
/home/j/.nimble/pkgs/bson-1.1.2/bson.nim(904, 6) Warning: 'pretty' is not GC-safe as it calls 'genExtendedJson' [GcUnsafe2]
/home/j/nm.nim(26, 1) template/generic instantiation of `routes` from here
/home/j/.nimble/pkgs/jester-0.4.3/jester.nim(1283, 35) template/generic instantiation of `async` from here
/home/j/.choosenim/toolchains/nim-1.2.6/lib/pure/asyncmacro.nim(278, 31) Error: 'matchIter' is not GC-safe as it calls 'pretty'
]#

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions