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

Unexpected Nil pointers on code that doesn't even have the potential to read Nil? #268

Open
Retkid opened this issue Sep 2, 2021 · 3 comments

Comments

@Retkid
Copy link

Retkid commented Sep 2, 2021

I've attached the full Strace of the execution encase my code isn't the culprit, but im confident it is.

pid 96499] <... newfstatat resumed>{st_mode=S_IFREG|0644, st_size=0, ...}, AT_EMPTY_PATH) = 0
[pid 96486] <... read resumed>"\v\4\330\24\0\0\1{\250_\3012\207FAILED\1\v\4\236\23\0\0\1{\250_\3012"..., 4096) = 34
[pid 96498] futex(0x7f98e400e7b8, FUTEX_WAIT_BITSET_PRIVATE, 0, {tv_sec=216981, tv_nsec=83038533}, FUTEX_BITSET_MATCH_ANY <unfinished ...>
[pid 96499] read(138, "max\n", 4096)    = 4
[pid 96499] close(138)                  = 0
[pid 96499] sysinfo({uptime=216977, loads=[177696, 133920, 118080], totalram=8260919296, freeram=1260814336, sharedram=636977152, bufferram=147357696, totalswap=10572787712, freeswap=6866649088, procs=1022, totalhigh=0, freehigh=0, mem_unit=1}) = 0
[pid 96499] sysinfo( <unfinished ...>
[pid 96486] epoll_wait(135,  <unfinished ...>
[pid 96499] <... sysinfo resumed>{uptime=216977, loads=[177696, 133920, 118080], totalram=8260919296, freeram=1260814336, sharedram=636977152, bufferram=147357696, totalswap=10572787712, freeswap=6866649088, procs=1022, totalhigh=0, freehigh=0, mem_unit=1}) = 0
[pid 96499] futex(0x7f98e400e7b8, FUTEX_WAIT_BITSET_PRIVATE, 0, {tv_sec=216981, tv_nsec=83401037}, FUTEX_BITSET_MATCH_ANY <unfinished ...>
[pid 96508] <... futex resumed>)        = -1 ETIMEDOUT (Connection timed out)
[pid 96508] futex(0x7f98e4875f18, FUTEX_WAKE_PRIVATE, 1) = 0
[pid 96508] write(2, "Traceback (most recent call last"..., 33Traceback (most recent call last)) = 33
[pid 96508] write(2, "\n", 1
)           = 1
[pid 96508] write(2, "/home/retkid/Desktop/downloads/f"..., 80/home/retkid/Desktop/downloads/fabric/src/main/nim/helloworld.nim(43) helloworld) = 80
[pid 96508] write(2, "\n", 1
)           = 1
[pid 96486] <... epoll_wait resumed>[{events=EPOLLIN, data={u32=134, u64=140290811756678}}], 1024, -1) = 1
[pid 96508] write(2, "/usr/lib/nim/pure/os.nim(3035) s"..., 36/usr/lib/nim/pure/os.nim(3035) sleep) = 36
[pid 96508] write(2, "\n", 1 <unfinished ...>

[pid 96486] read(134,  <unfinished ...>
[pid 96508] <... write resumed>)        = 1
[pid 96486] <... read resumed>"\v\10\0\0\1{\250_\3017\267org.gradle.internal.b"..., 4096) = 1053
[pid 96508] write(2, "SIGSEGV: Illegal storage access."..., 60SIGSEGV: Illegal storage access. (Attempt to read from nil?)) = 60
[pid 96508] write(2, "\n", 1
)           = 1
[pid 96508] futex(0x7f98e400e7b8, FUTEX_WAKE_PRIVATE, 2147483647 <unfinished ...>
[pid 96486] futex(0x7f98e4012478, FUTEX_WAIT_BITSET_PRIVATE, 0, {tv_sec=216976, tv_nsec=93525597}, FUTEX_BITSET_MATCH_ANY <unfinished ...>
[pid 96508] <... futex resumed>)        = 2
[pid 96499] <... futex resumed>)        = 0
[pid 96498] <... futex resumed>)        = 0
[pid 96508] write(1, "\n", 1 <unfinished ...>

[pid 96499] futex(0x7f98e400e768, FUTEX_WAKE_PRIVATE, 1 <unfinished ...>
[pid 96498] futex(0x7f98e400e768, FUTEX_WAKE_PRIVATE, 1 <unfinished ...>
[pid 96508] <... write resumed>)        = 1

the code i was running is...

proc helloworld() {.cdecl, exportc, dynlib, thread.} =
  var client: Socket
  var address = "127.0.0.1"
  var socket = newSocket()
  let input : string = "test.1.100.uuid1982"
  var container: seq[string]
  os.sleep(10000)

and the java code:

            Thread{server()}.start()
            val helloworld = libclass.libhelloworld()
            Thread{helloworld.helloworld()}.start()

and the libclass code

class libclass{
    companion object {
       fun libhelloworld() : helloworld{
          return LibraryLoader.create(helloworld::class.java).load("${gettempdir()}/${libmodify("helloworld")}")}
    }

I suspect im doing something wrong and my loading function is too simple. Any insight would be useful.
trace.txt

@basshelal
Copy link
Contributor

I'm unsure what's causing the errors but I can try to help guide you in a direction to hopefully make debugging easier.

In your trace, the last calls were to futexes and gettid(), both thread and locking related things. I'm guessing you're doing something illegal by using multiple threads?

Can you run the same kind of code natively and have it running? Generally, if it won't run successfully on native then it won't run on the JVM either.

Otherwise I'd try to have all the code running on one Thread and see what that does

@Retkid
Copy link
Author

Retkid commented Sep 6, 2021

I'm unsure what's causing the errors but I can try to help guide you in a direction to hopefully make debugging easier.

In your trace, the last calls were to futexes and gettid(), both thread and locking related things. I'm guessing you're doing something illegal by using multiple threads?

Can you run the same kind of code natively and have it running? Generally, if it won't run successfully on native then it won't run on the JVM either.

Otherwise I'd try to have all the code running on one Thread and see what that does

even if it all works on one thread, im running a server and it has to be on a separate thread to be asynchronous

@headius
Copy link
Member

headius commented Sep 7, 2021

If it works on one thread then there may be some interaction between the calls you want to make and the way the JVM handles threads and locking. That isn't to say it can't use threads, but there could be some hidden interactions (e.g. lazy initialization, internal resource locking, ...) that would need to be considered before starting the threads.

Would it be possible for you to create a small example repository that gives us an easy way to reproduce? I don't see anything obvious from your example code (or at least nothing that would point to a bug in jnr-ffi) so we need a little more help finding your issue.

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

3 participants