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

SIGSEGV sending a puppy Response object down a Channel with --gc:orc #18950

Open
oakes opened this issue Oct 4, 2021 · 0 comments
Open

SIGSEGV sending a puppy Response object down a Channel with --gc:orc #18950

oakes opened this issue Oct 4, 2021 · 0 comments

Comments

@oakes
Copy link

oakes commented Oct 4, 2021

I made a simple program that launches a worker thread that is supposed to make requests with puppy and send the response down a channel. It fails with a SIGSEGV on the latest devel when gc:orc is enabled.

Example

Install the latest puppy via nimble install puppy and then save the following to chtest.nim:

import puppy

type
  Action = object
    request: Request
    response: ptr Channel[Response]
  Client = ref object
    requestThread: Thread[Client]
    action: ptr Channel[Action]

proc recvAction(client: Client) {.thread.} =
  while true:
    let action = client.action[].recv()
    action.response[].send(fetch(action.request))

proc start*(client: var Client) =
  client.action = cast[ptr Channel[Action]](
    allocShared0(sizeof(Channel[Action]))
  )
  client.action[].open()
  createThread(client.requestThread, recvAction, client)

var c = Client()
start(c)

let res = cast[ptr Channel[Response]](
  allocShared0(sizeof(Channel[Response]))
)
res[].open()
c.action[].send(Action(request: Request(url: parseUrl("http://tired.com"), verb: "get"), response: res))
echo res[].recv()[]

Then run it with:

nim c -r --threads:on --gc:orc chtest.nim

Current Output

/home/sekao/.choosenim/toolchains/nim-#version-1-6/lib/pure/strutils.nim(368) fetch
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

(this is on linux....output differs on mac OS and windows)

Expected Output

(url: http://tired.com, headers: @[(key: "Date", value: "Mon, 04 Oct 2021 19:44:19 GMT"), (key: "Server", value: "Apache/2.2.16 (Debian)"), (key: "Last-Modified", value: "Mon, 29 Sep 2003 08:34:25 GMT"), (key: "ETag", value: "\"3d7130-b8-3c873c3fc0640\""), (key: "Accept-Ranges", value: "bytes"), (key: "Vary", value: "Accept-Encoding"), (key: "Content-Encoding", value: "gzip"), (key: "Content-Length", value: "154"), (key: "Content-Type", value: "text/html")], code: 200, body: "<HTML>\n<HEAD>\n<TITLE>Are you tired?</TITLE>\n</HEAD>\n<BODY BGCOLOR=#FFFFFF>\n<PRE>\n<CENTER>\n\n\n\nAre you tired?\n\nTell <a href=\"mailto:tired@tired.com\">us</a> why.\n</CENTER>\n</PRE>\n</BODY>\n", error: "")
$ nim -v
Nim Compiler Version 1.5.1 [Linux: amd64]
Compiled at 2021-10-04
Copyright (c) 2006-2021 by Andreas Rumpf

active boot switches: -d:release

I also tried nim 1.4.8 with similar results...

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

No branches or pull requests

1 participant