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

[SR-10319] sourcekit-lsp crashing when opening a swift package with VSC #618

Open
swift-ci opened this issue Apr 5, 2019 · 5 comments
Open

Comments

@swift-ci
Copy link

swift-ci commented Apr 5, 2019

Previous ID SR-10319
Radar None
Original Reporter cukier (JIRA User)
Type Bug

Attachment: Download

Environment

OS:
Ubuntu 18.04 and 18.10 64-bit

toolchain:
swift-5.0-RELEASE-ubuntu18.04

Additional Detail from JIRA
Votes 0
Component/s libdispatch, SourceKit-LSP
Labels Bug
Assignee ktopley-apple (JIRA)
Priority Medium

md5: 973ab2af9bcd0cc9584a10897d3e9f9e

Issue Description:

When I open a package directory in Visual Studio Code, the language server crashes immediately. If package was never built, or I delete the .build directory, the language server works perfectly.
Steps to reproduce:

$mkdir bug_report_package
$cd bug_report_package
$swift package init --type executable
$swift run
$code .
click on main.swift file in VSC

More info about how I got here is in this thread: https://forums.swift.org/t/using-sourcekit-lsp-on-ubuntu-18-10/22598

lldb output:

cukier@papryka:~$ sudo /home/cukier/Developer/swift-5.0-RELEASE-ubuntu18.04/usr/bin/lldb
(lldb) process attach -n sourcekit-lsp
Process 10513 stopped
* thread #​1, name = 'sourcekit-lsp', stop reason = signal SIGSTOP
    frame #​0: 0x00007f30c0e6a3f6 libc.so.6`__GI___sigsuspend(set=0x00007f30c1b5b950) at sigsuspend.c:26:10
  thread #​2, name = 'sourcekit-lsp', stop reason = signal SIGSTOP
    frame #​0: 0x00007f30c2bfa142 libpthread.so.0`do_futex_wait at futex-internal.h:205:13
  thread #​3, name = 'sourcekit-lsp', stop reason = signal SIGSTOP
    frame #​0: 0x00007f30c2bfa142 libpthread.so.0`do_futex_wait at futex-internal.h:205:13
  thread #​4, name = 'sourcekit-lsp', stop reason = signal SIGSTOP
    frame #​0: 0x00007f30c2bfa142 libpthread.so.0`do_futex_wait at futex-internal.h:205:13
  thread #​5, name = 'sourcekit-lsp', stop reason = signal SIGSTOP
    frame #​0: 0x00007f30c2bfa142 libpthread.so.0`do_futex_wait at futex-internal.h:205:13
  thread #​6, name = 'sourcekit-lsp', stop reason = signal SIGSTOP
    frame #​0: 0x00007f30c2bfa142 libpthread.so.0`do_futex_wait at futex-internal.h:205:13
  thread #​7, name = 'sourcekit-lsp', stop reason = signal SIGSTOP
    frame #​0: 0x00007f30c2bfa142 libpthread.so.0`do_futex_wait at futex-internal.h:205:13
  thread #​8, name = 'sourcekit-lsp', stop reason = signal SIGSTOP
    frame #​0: 0x00007f30c2bfa142 libpthread.so.0`do_futex_wait at futex-internal.h:205:13
  thread #​9, name = 'sourcekit-lsp', stop reason = signal SIGSTOP
    frame #​0: 0x00007f30c0f4410f libc.so.6`epoll_wait(epfd=3, events=0x00007f30b1ffaa30, maxevents=16, timeout=-1) at epoll_wait.c:30:10
  thread #​10, name = 'sourcekit-lsp', stop reason = signal SIGSTOP
    frame #​0: 0x00007f30c2bf72eb libpthread.so.0`__pthread_cond_wait at futex-internal.h:88:13
  thread #​11, name = 'sourcekit-lsp', stop reason = signal SIGSTOP
    frame #​0: 0x00007f30c2bfa142 libpthread.so.0`do_futex_wait at futex-internal.h:205:13
  thread #​12, name = 'sourcekit-lsp', stop reason = signal SIGSTOP
    frame #​0: 0x00007f30c2bfac24 libpthread.so.0`__libc_read at read.c:26:10
  thread #​13, name = 'sourcekit-lsp', stop reason = signal SIGSTOP
    frame #​0: 0x00007f30c2bfac24 libpthread.so.0`__libc_read at read.c:26:10
Target 0: (sourcekit-lsp) stopped.

Executable module set to "/home/cukier/Developer/sourcekit-lsp/.build/x86_64-unknown-linux/debug/sourcekit-lsp".
Architecture set to: x86_64--linux-gnu.
(lldb) continue
Process 10513 resuming
Process 10513 stopped and restarted: thread 1 received signal: SIGCHLD
(lldb) error: ld-linux-x86-64.so.2 0xffffffff0005f117: adding range [0x14167-0x141ca) which has a base that is less than the function's low PC 0x148c0. Please file a bug and attach the file at the start of this error message
error: ld-linux-x86-64.so.2 0xffffffff0005f117: adding range [0x141e0-0x141e6) which has a base that is less than the function's low PC 0x148c0. Please file a bug and attach the file at the start of this error message
error: ld-linux-x86-64.so.2 0xffffffff0005f184: adding range [0x14167-0x141ca) which has a base that is less than the function's low PC 0x148c0. Please file a bug and attach the file at the start of this error message
error: ld-linux-x86-64.so.2 0xffffffff0005f184: adding range [0x141e0-0x141e6) which has a base that is less than the function's low PC 0x148c0. Please file a bug and attach the file at the start of this error message
Process 10513 stopped
* thread #​14, name = 'sourcekit-lsp', stop reason = signal SIGILL: illegal instruction operand
    frame #​0: 0x00007f30c1b3d5cc libdispatch.so`_dispatch_Block_copy + 44
libdispatch.so`_dispatch_Block_copy:
->  0x7f30c1b3d5cc <+44>: ud2    
    0x7f30c1b3d5ce:       nop    
libdispatch.so`_dispatch_call_block_and_release:
    0x7f30c1b3d5d0 <+0>:  pushq  %rbx
    0x7f30c1b3d5d1 <+1>:  movq   %rdi, %rbx
Target 0: (sourcekit-lsp) stopped.
(lldb) bt
* thread #&#8203;14, name = 'sourcekit-lsp', stop reason = signal SIGILL: illegal instruction operand
  * frame #&#8203;0: 0x00007f30c1b3d5cc libdispatch.so`_dispatch_Block_copy + 44
    frame #&#8203;1: 0x00007f309c07f290
    frame #&#8203;2: 0x000055d57d60ead6 sourcekit-lsp`std::_Function_handler<void (indexstore::IndexStore::UnitEventNotification), (anonymous namespace)::IndexDatastoreImpl::init(std::shared_ptr<indexstore::IndexStore>, std::shared_ptr<IndexStoreDB::index::SymbolIndex>, std::shared_ptr<IndexStoreDB::index::IndexSystemDelegate>, std::shared_ptr<IndexStoreDB::CanonicalPathCache>, bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)::$_6>::_M_invoke(__functor=0x00007f309c04c580, __args=0x00007f30abffe708) at std_function.h:297:2
    frame #&#8203;3: 0x000055d57d61eb8b sourcekit-lsp`std::function<void (indexstore::IndexStore::UnitEventNotification)>::operator(this=0x00007f309c04c580, __args=UnitEventNotification @ 0x00007f30abffe708)(indexstore::IndexStore::UnitEventNotification) const at std_function.h:687:14
    frame #&#8203;4: 0x000055d57d61ea34 sourcekit-lsp`indexstore::IndexStore::setUnitEventHandler(this=0x00007f309c04c580, evt_note=0x00007f30abffe800)>)::'lambda'(void*)::operator()(void*) const at IndexStoreCXX.h:220:9
    frame #&#8203;5: 0x000055d57d61e5c2 sourcekit-lsp`std::_Function_handler<void (void*), indexstore::IndexStore::setUnitEventHandler(std::function<void (indexstore::IndexStore::UnitEventNotification)>)::'lambda'(void*)>::_M_invoke(__functor=0x00007f309c07f340, __args=0x00007f30abffe7b0) at std_function.h:297:2
    frame #&#8203;6: 0x000055d57d61eeb8 sourcekit-lsp`std::function<void (void*)>::operator(this=0x00007f309c07f340, __args=0x00007f30abffe800)(void*) const at std_function.h:687:14
    frame #&#8203;7: 0x000055d57d61e345 sourcekit-lsp`indexstore::IndexStore::event_handler(ctx=0x00007f309c07f340, evt=0x00007f30abffe800) at IndexStoreCXX.h:230:5
    frame #&#8203;8: 0x00007f30b8f9c703 libIndexStore.so`std::_Function_handler<void (clang::index::IndexDataStore::UnitEventNotification), indexstore_store_set_unit_event_handler_f::$_1>::_M_invoke(std::_Any_data const&, clang::index::IndexDataStore::UnitEventNotification&&) + 35
    frame #&#8203;9: 0x00007f30b8f9e054 libIndexStore.so`std::_Function_handler<void (llvm::ArrayRef<clang::DirectoryWatcher::Event>, bool), (anonymous namespace)::IndexDataStoreImpl::startEventListening(bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)::$_0>::_M_invoke(std::_Any_data const&, llvm::ArrayRef<clang::DirectoryWatcher::Event>&&, bool&&) + 468
    frame #&#8203;10: 0x00007f30b8fb26cc libIndexStore.so`clang::DirectoryWatcher::Implementation::initialize(llvm::StringRef, std::function<void (llvm::ArrayRef<clang::DirectoryWatcher::Event>, bool)>, bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)::$_1::operator()() const + 1868
    frame #&#8203;11: 0x00007f30c10ea63f libstdc++.so.6`___lldb_unnamed_symbol439$$libstdc++.so.6 + 15
    frame #&#8203;12: 0x00007f30c2bf1164 libpthread.so.0`start_thread(arg=<unavailable>) at pthread_create.c:486:8
    frame #&#8203;13: 0x00007f30c0f43def libc.so.6`__GI___clone at clone.S:95
(lldb) 
@benlangmuir
Copy link
Member

I can reproduce this from 18.10 running in docker.

@benlangmuir
Copy link
Member

This reproduces on 18.04 as well. Maybe the libIndexStore from the 5.0 toolchain isn't working on Linux.

@benlangmuir
Copy link
Member

This reproduces in master branch development snapshots as well. I tested some historical snapshots and found:

OKAY:  swift-DEVELOPMENT-SNAPSHOT-2019-03-17-a
CRASH: swift-DEVELOPMENT-SNAPSHOT-2019-03-25-a

The crash is not coming from the compiled code, but from the runtime libraries. If I run sourcekit-lsp built with 03-17-a using the runtime libraries from 03-25-a is also crashes, and if I run code built with 03-25-a using the 03-17-a libraries it does not crash.

I believe this was triggered by a change to libdispatch, based on the stack trace and the fact there were some huge changes to dispatch in this time period. Note these are on both master and 5.0 branches.

7e7677b Merge pull request #&#8203;466 from apple/kwt-ubuntu1804-clang-workaround
6c5b3ba Merge pull request #&#8203;465 from triplef/fix-gettid-android
319bd33 Merge pull request #&#8203;452 from drodriguez/fix-regex-windows
6e1825a Merge pull request #&#8203;458 from triplef/fix-missing-queue-defs
cbd70d1 Merge pull request #&#8203;461 from tachoknight/master
592749b Merge branch 'master' of https://github.com/apple/swift-corelibs-libdispatch
9d485ca Merge pull request #&#8203;459 from triplef/fix-sched-yield-android
ef9364c Merge pull request #&#8203;463 from triplef/fix-printf-dsma-value
f20349f Merge pull request #&#8203;457 from triplef/fix-signatures
7a74af4 Merge pull request #&#8203;460 from triplef/fix-cmake-private-install
60fdf80 Merge pull request #&#8203;448 from triplef/fix-printf-ptr
4659503 Merge pull request #&#8203;453 from compnerd/windows-improvements
d44acc0 Merge pull request #&#8203;447 from apple/kwt-test-darwin-libdispatch-1121-merge-master

We already had a compile-time crash in clang related to #447 (worked around in #466).

@benlangmuir
Copy link
Member

This seems to be triggered by the QoS we're trying to set. On Linux we don't have `qos.h`, so we use the old DISPATCH_QUEUE_PRIORITY_LOW, which is documented as being equivalent to UTILITY.

Here's a reproducer (I have the toolchain installed in ~/swift, so you may need to fix the paths). This reproduces with any recent master development toolchain. It fails while copying the 3rd block.

$ cat test.cpp
#include <dispatch/dispatch.h>
#include <Block.h>
#include <stdio.h>

int main() {
    auto q = dispatch_queue_create("myqueue", 0);
    
    dispatch_async(q, ^{
      puts("myBlock1\n");
    });

    dispatch_async(q, dispatch_block_create(DISPATCH_BLOCK_INHERIT_QOS_CLASS, ^{
      puts("myBlock2\n");
    }));

    dispatch_async(q, dispatch_block_create_with_qos_class(DISPATCH_BLOCK_INHERIT_QOS_CLASS, DISPATCH_QUEUE_PRIORITY_LOW, 0, ^{
      puts("myBlock3\n");
    }));

    dispatch_main();
}

$ ~/swift/usr/bin/clang test.cpp -I ~/swift/usr/lib/swift/ -I ~/swift/usr/lib/swift/Block/ -fblocks -ldispatch -lBlocksRuntime -L ~/swift/usr/lib/  -o test

$ LD_LIBRARY_PATH=$HOME/swift/usr/lib  ./test  
myBlock1

myBlock2

Illegal instruction

@benlangmuir
Copy link
Member

I put a workaround into indexstore-db (apple/indexstore-db#27 so if anyone is hitting this in sourcekit-lsp, please update to the latest master (or swift-5.1-branch) and try again (make sure to `swift package update` to get the latest indexstore-db version).

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
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

2 participants