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

memory corrupted; possibly by try/catch using import segfaults #9752

Open
timotheecour opened this issue Nov 19, 2018 · 11 comments
Open

memory corrupted; possibly by try/catch using import segfaults #9752

timotheecour opened this issue Nov 19, 2018 · 11 comments

Comments

@timotheecour
Copy link
Member

timotheecour commented Nov 19, 2018

/cc @Araq
see reproducible test case here: #9751

these all work:

nim c -r bug/trunall_13_tests_stdlib_tstdlib_various
nim c -r bug/trunall_62_tests_stdlib_twalker
nim c -r bug/trunall_63_tests_stdlib_tmarshal
nim c -r bug/trunall_64_tests_stdlib_tparsesql

but this fails if importing all of the above:

nim c -r bug/run_bug.nim

with bug/run_bug.nim:

import trunall_13_tests_stdlib_tstdlib_various
import trunall_62_tests_stdlib_twalker
import trunall_63_tests_stdlib_tmarshal
import trunall_64_tests_stdlib_tparsesql
true
alpha 100
omega 200
tests/stdlib/tparsesql.nim
/Users/timothee/git_clone/nim/Nim/tests/stdlib/tstdlib_various.nim(175) trunall_13_tests_stdlib_tstdlib_various
/Users/timothee/git_clone/nim/Nim/tests/stdlib/tstdlib_various.nim(167) main
[[reraised from:
/Users/timothee/git_clone/nim/Nim/tests/stdlib/tstdlib_various.nim(175) trunall_13_tests_stdlib_tstdlib_various
/Users/timothee/git_clone/nim/Nim/tests/stdlib/tstdlib_various.nim(167) main
]]
[[reraised from:
/Users/timothee/git_clone/nim/Nim/tests/stdlib/tstdlib_various.nim(175) trunall_13_tests_stdlib_tstdlib_various
/Users/timothee/git_clone/nim/Nim/tests/stdlib/tstdlib_various.nim(167) main
]]
[[reraised from:
/Users/timothee/git_clone/nim/Nim/tests/stdlib/tstdlib_various.nim(175) trunall_13_tests_stdlib_tstdlib_various
/Users/timothee/git_clone/nim/Nim/tests/stdlib/tstdlib_various.nim(167) main
]]
[[reraised from:
/Users/timothee/git_clone/nim/Nim/tests/stdlib/tstdlib_various.nim(175) trunall_13_tests_stdlib_tstdlib_various
/Users/timothee/git_clone/nim/Nim/tests/stdlib/tstdlib_various.nim(167) main
]]
[[reraised from:
/Users/timothee/git_clone/nim/Nim/tests/stdlib/tstdlib_various.nim(175) trunall_13_tests_stdlib_tstdlib_various
/Users/timothee/git_clone/nim/Nim/tests/stdlib/tstdlib_various.nim(167) main
]]
[[reraised from:
/Users/timothee/git_clone/nim/Nim/tests/stdlib/tparsesql.nim(162) trunall_64_tests_stdlib_tparsesql
/Users/timothee/git_clone/nim/Nim/lib/pure/parsesql.nim(1514) parseSQL
/Users/timothee/git_clone/nim/Nim/lib/pure/parsesql.nim(1506) parseSQL
/Users/timothee/git_clone/nim/Nim/lib/pure/parsesql.nim(1181) parse
/Users/timothee/git_clone/nim/Nim/lib/pure/parsesql.nim(1160) parseStmt
/Users/timothee/git_clone/nim/Nim/lib/pure/parsesql.nim(977) parseIndexDef
/Users/timothee/git_clone/nim/Nim/lib/pure/parsesql.nim(576) newNode
/Users/timothee/git_clone/nim/Nim/lib/system/gc.nim(496) newObjRC1
/Users/timothee/git_clone/nim/Nim/lib/system/alloc.nim(781) rawAlloc
]]
Error: unhandled exception:  [NilAccessError]
Error: execution of an external program failed: '/Users/timothee/git_clone/nim/Nim/bug/run_bug '

nim --version
Nim Compiler Version 0.19.9 [MacOSX: amd64]
Compiled at 2018-11-16
Copyright (c) 2006-2018 by Andreas Rumpf

git hash: 6279b05
active boot switches: -d:release

note

I ran into this while working on #9581

note

wondering if it's because of import segfaults in tstdlib_various

@timotheecour timotheecour changed the title memory corrupted memory corrupted; possibly by import segfaults Nov 19, 2018
@timotheecour timotheecour changed the title memory corrupted; possibly by import segfaults memory corrupted; possibly by try/catch using import segfaults Nov 19, 2018
@stale
Copy link

stale bot commented Aug 4, 2020

This issue has been automatically marked as stale because it has not had recent activity. If you think it is still a valid issue, write a comment below; otherwise it will be closed. Thank you for your contributions.

@stale stale bot added the stale Staled PR/issues; remove the label after fixing them label Aug 4, 2020
@ringabout
Copy link
Member

ringabout commented Nov 20, 2020

@timotheecour

It seems not to happen anymore. Though I couldn't find twalker.nim. I will make a PR to show this/
It seems to be fixed by #15342

@stale stale bot removed the stale Staled PR/issues; remove the label after fixing them label Nov 20, 2020
@ringabout
Copy link
Member

I think it is only related to two files

include "../tests/stdlib/tstdlib_various.nim"
include "../tests/stdlib/tmarshal.nim"

Gave:

abc
def
definition
prefix
xyz
def
definition
Hi Andreas! How do you feel, Rumpf?

@[0, 2, 1]
@[1, 0, 2]
@[1, 2, 0]
@[2, 0, 1]
@[2, 1, 0]
@[2, 0, 1]
@[1, 2, 0]
@[1, 0, 2]
@[0, 2, 1]
@[0, 1, 2]
055this should be the casehugh@["(", "+", " 1", " 2", ")"]
caught a crash!
caught a crash!
caught a crash!
caught a crash!
caught a crash!
caught a crash!
[5]
[4, 5]
[3, 4, 5]
[2, 3, 4, 5]
[2, 3, 4, 5, 6]
[1, 2, 3, 4, 5, 6]
true
<h1><a href="http://force7.de/nim">Nim</a></h1>
{"age": 12, "bio": "Я Cletus", "blob": [65, 66, 67, 128], "name": "Cletus"}
true
true
alpha 100
omega 200
Some(null)
D:\QQPCmgr\Desktop\Nim\tests\stdlib\tstdlib_various.nim(175) run_bug
D:\QQPCmgr\Desktop\Nim\tests\stdlib\tstdlib_various.nim(167) main
[[reraised from:
D:\QQPCmgr\Desktop\Nim\tests\stdlib\tstdlib_various.nim(175) run_bug
D:\QQPCmgr\Desktop\Nim\tests\stdlib\tstdlib_various.nim(167) main
]]
[[reraised from:
D:\QQPCmgr\Desktop\Nim\tests\stdlib\tstdlib_various.nim(175) run_bug
D:\QQPCmgr\Desktop\Nim\tests\stdlib\tstdlib_various.nim(167) main
]]
[[reraised from:
D:\QQPCmgr\Desktop\Nim\tests\stdlib\tstdlib_various.nim(175) run_bug
D:\QQPCmgr\Desktop\Nim\tests\stdlib\tstdlib_various.nim(167) main
]]
[[reraised from:
D:\QQPCmgr\Desktop\Nim\tests\stdlib\tstdlib_various.nim(175) run_bug
D:\QQPCmgr\Desktop\Nim\tests\stdlib\tstdlib_various.nim(167) main
]]
[[reraised from:
D:\QQPCmgr\Desktop\Nim\tests\stdlib\tstdlib_various.nim(175) run_bug
D:\QQPCmgr\Desktop\Nim\tests\stdlib\tstdlib_various.nim(167) main
]]
[[reraised from:
D:\QQPCmgr\Desktop\Nim\tests\stdlib\tmarshal.nim(142) run_bug
C:\Users\blue\.choosenim\toolchains\nim-#devel\lib\pure\marshal.nim(343) to
C:\Users\blue\.choosenim\toolchains\nim-#devel\lib\pure\marshal.nim(276) loadAny
C:\Users\blue\.choosenim\toolchains\nim-#devel\lib\pure\marshal.nim(196) loadAny
C:\Users\blue\.choosenim\toolchains\nim-#devel\lib\pure\marshal.nim(211) loadAny
C:\Users\blue\.choosenim\toolchains\nim-#devel\lib\core\typeinfo.nim(330) setPointer
C:\Users\blue\.choosenim\toolchains\nim-#devel\lib\system\assign.nim(139) genericAssign
C:\Users\blue\.choosenim\toolchains\nim-#devel\lib\system\assign.nim(134) genericAssignAux
]]

If I use devel, it works ad expected:

abc
def
definition
prefix
xyz
def
definition
Hi Andreas! How do you feel, Rumpf?

@[0, 2, 1]
@[1, 0, 2]
@[1, 2, 0]
@[2, 0, 1]
@[2, 1, 0]
@[2, 0, 1]
@[1, 2, 0]
@[1, 0, 2]
@[0, 2, 1]
@[0, 1, 2]
055this should be the casehugh@["(", "+", " 1", " 2", ")"]
caught a crash!
caught a crash!
caught a crash!
caught a crash!
caught a crash!
caught a crash!
[5]
[4, 5]
[3, 4, 5]
[2, 3, 4, 5]
[2, 3, 4, 5, 6]
[1, 2, 3, 4, 5, 6]
true
<h1><a href="http://force7.de/nim">Nim</a></h1>
{"age": 12, "bio": "Я Cletus", "blob": [65, 66, 67, 128], "name": "Cletus"}
true
true
alpha 100
omega 200
Some(null)
None[JsonNode]
(numeric: "")

@timotheecour
Copy link
Member Author

@xflywind cool; if possible could you try to minimize a bit while maintaining the crash before that PR and succeeding after that PR?

@ringabout
Copy link
Member

Some tests are changing and doesn't work in Nim v 1.2.6
I will try to minimize that.

@Araq
Copy link
Member

Araq commented Nov 23, 2020

Instead remove import segfaults from the tests, I don't want to support it further, it's stupid. At some point one has to let processes crash and invest some effort into testing one's code.

@timotheecour
Copy link
Member Author

timotheecour commented Nov 23, 2020

import segfaults is useful I don't see why keeping at least 1 test is a maintenance burden.
I have real use cases for import segfaults, including for a repl I'm working on (already usable), where the process can't crash.
The repl, unlike nim secret, works at RT (so avoids some limitations of VM), and unlike inim, doesn't recompile the whole program on each command, and is in particular faster.

There are other use cases for processes that can't crash that take user input such as shared library plugins.

@johnnovak
Copy link
Contributor

johnnovak commented May 1, 2021

I don't want to support it further, it's stupid. At some point one has to let processes crash and invest some effort into testing one's code.

Yes, and in an ideal world, you'd have all the time (and ability!) to produce code with zero bugs. It doesn't happen in the real world, though, does it?

It's not just about "processes" that you run on your machine, what about applications shipped to users? Being able to catch and log any error or segfault is an extremely useful (and I'd even say, essential) requirement for such apps; then the user can provide the crash log in the bug report.

This has been a standard feature of all high-level languages for decades. I know Nim is not exactly "high level" in the same sense, but we can still aim to be better than C in this regard.

@timotheecour
Copy link
Member Author

timotheecour commented May 1, 2021

FWIW, I wrote a branch which allowed to raise a Defect upon nil dereferencing (without resorting to signals, but instead by codegen instrumentation), which can help for debugging, in particular can give column info and is safe since doesn't rely on signals.

(exp_SIGSEGV_debug, no PR ready though, but it did work)
(controlled by a flag)

@Araq
Copy link
Member

Araq commented May 1, 2021

Yes, and in an ideal world, you'd have all the time (and ability!) to produce code with zero bugs. It doesn't happen in the real world, though, does it?

Yeah, exactly. I haven't been able to write segfaults without bugs and I don't have all the time to maintain it either. Ironic, isn't it.

@johnnovak
Copy link
Contributor

Yes, and in an ideal world, you'd have all the time (and ability!) to produce code with zero bugs. It doesn't happen in the real world, though, does it?

Yeah, exactly. I haven't been able to write segfaults without bugs and I don't have all the time to maintain it either. Ironic, isn't it.

Good point, but I find this to be an important part of the core language.

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

No branches or pull requests

4 participants