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

[game] crash when using game_play #162

Closed
hackfisher opened this issue Oct 9, 2015 · 15 comments
Closed

[game] crash when using game_play #162

hackfisher opened this issue Oct 9, 2015 · 15 comments
Assignees

Comments

@hackfisher
Copy link

Process 1070 stopped
* thread #1: tid = 0xf42b, 0x00002684ed019c13, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x00002684ed019c13
->  0x2684ed019c13: pushq  (%r10)
    0x2684ed019c16: addq   $0x1, %rcx
    0x2684ed019c1a: cmpq   %rax, %rcx
    0x2684ed019c1d: jne    0x2684ed019c0f
(lldb) up
frame #1: 0x00002684ed018a62
    0x2684ed018a62: movabsq $0x10529b2d8, %r10
    0x2684ed018a6c: popq   (%r10)
    0x2684ed018a6f: addq   $0x0, %rsp
    0x2684ed018a73: popq   %rbx
(lldb) up
frame #2: 0x0000000100e89a3e play_testnet_client`v8::internal::Invoke(is_construct=<unavailable>, function=<unavailable>, receiver=<unavailable>, argc=3, args=0x00000001046efe90) + 766 at execution.cc:128
   125      Object*** argv = reinterpret_cast<Object***>(args);
   126      if (FLAG_profile_deserialization) PrintDeserializedCodeInfo(function);
   127      value =
-> 128          CALL_GENERATED_CODE(stub_entry, function_entry, func, recv, argc, argv);
   129    }
   130
   131  #ifdef VERIFY_HEAP
(lldb) up
frame #3: 0x0000000100e89573 play_testnet_client`v8::internal::Execution::Call(isolate=<unavailable>, callable=<unavailable>, receiver=<unavailable>, argc=3, argv=0x00000001046efe90, convert_receiver=<unavailable>) + 371 at execution.cc:179
   176      }
   177    }
   178
-> 179    return Invoke(false, func, receiver, argc, argv);
   180  }
   181
   182
(lldb) up
frame #4: 0x0000000100cfc411 play_testnet_client`v8::Function::Call(this=0x00000001044cc040, context=<unavailable>, recv=<unavailable>, argc=3, argv=0x00000001046efe90) + 289 at api.cc:4397
   4394   Local<Value> result;
   4395   has_pending_exception =
   4396       !ToLocal<Value>(
-> 4397           i::Execution::Call(isolate, self, recv_obj, argc, args, true),
   4398           &result);
   4399   RETURN_ON_FAILED_EXECUTION(Value);
   4400   RETURN_ESCAPED(result);
(lldb) up
frame #5: 0x0000000100a2afbc play_testnet_client`bts::game::v8_game_engine::play(this=<unavailable>, game_id=<unavailable>, blockchain=bts::blockchain::chain_database_ptr at 0x00000001046f00d0, w=bts::wallet::wallet_ptr at 0x00000001046f00c0, var=0x00000001046f0c90, sign=<unavailable>) + 1532 at v8_game.cpp:268
   265             argv[2] = v8_helper::cpp_to_json(isolate, _input);
   266
   267             wlog("Start game play script.. with var ${v}", ("v", var));
-> 268             Local<Value> result = play_func->Call(context->Global(), 3, argv);
   269
   270             if ( result.IsEmpty() )
   271             {
(lldb) up
frame #6: 0x000000010015068e play_testnet_client`bts::wallet::wallet::play_game(this=<unavailable>, game_name=<unavailable>, params=<unavailable>, sign=<unavailable>) + 2142 at wallet.cpp:3712
   3709            FC_CAPTURE_AND_THROW( unknown_game_id, (game_name) );
   3710
   3711        auto engine = my->_game_client->get_v8_engine( game_name );
-> 3712        auto record = engine->play(game_rec->id, my->_blockchain, shared_from_this(), params, sign);
   3713
   3714        return record;
   3715
(lldb) up
frame #7: 0x000000010081b057 play_testnet_client`bts::client::detail::client_impl::game_play(this=0x0000000104454b00, game_name=<unavailable>, param=<unavailable>) + 39 at game_api.cpp:40
   37
   38   wallet_transaction_record client_impl::game_play(const std::string& game_name, const fc::variant& param )
   39   {
-> 40       auto record = _wallet->play_game(game_name, param, true);
   41       _wallet->cache_transaction(record);
   42       network_broadcast_transaction(record.trx);
   43       return record;
@hackfisher
Copy link
Author

It does not crash on linux:

default (unlocked) >>> game_play dice {"from_account_name":"gameking","amount":10,"odds":2,"guess":1}
20010 insufficient_funds: insufficient funds

    {"from_account_name":"gameking","amount_to_withdraw":{"amount":1000,"asset_id":1},"balance_records":[]}
    th_a  wallet.cpp:69 withdraw_to_transaction

    {"amount_to_withdraw":{"amount":1000,"asset_id":1},"from_account_name":"gameking","trx":{"expiration":"2015-10-09T09:38:46","reserved":null,"operations":[],"signatures":[]},"required_signatures":[]}
    th_a  wallet.cpp:97 withdraw_to_transaction

    {"prams":{"from_account_name":"gameking","amount":10,"odds":2,"guess":1}}
    th_a  wallet.cpp:3717 play_game

    {}
    th_a  common_api_client.cpp:7978 game_play

    {"command":"game_play"}
    th_a  cli.cpp:626 execute_command

@hackfisher
Copy link
Author

Seems have relation to this line:

JSON:Parser?

@hackfisher
Copy link
Author

game_create dice gameking 'https://raw.githubusercontent.com/dacsunlimited/dacplay-game-samples/master/dice/dice.js', '000', 'The game of dice', “"

wallet_gia_create gameking dice DICE DICE DICE 0.01 10000 1000


game_buy_chips gameking 10 DICE

game_play dice {"from_account_name":"gameking","amount":10,"odds":2,"guess":1}

@hackfisher
Copy link
Author

Here is a demo of V8 Function Call, may be we should try persistent the function?

https://v8.googlecode.com/svn/trunk/samples/process.cc

@hackfisher
Copy link
Author

After remove the parameters, it do not crash now, but another error come out:

default (unlocked) >>> game_play dice {"from_account_name":"gameking","amount":10,"odds":2,"guess":1}
100013 failed_run_script: failed to run script

    {"v8_helper::ReportException(isolate, &try_catch)":"undefined:0: <string conversion failed>\n<string conversion failed>\n\n"}
    th_a  v8_game.cpp:275 play

    {"prams":{"from_account_name":"gameking","amount":10,"odds":2,"guess":1}}
    th_a  wallet.cpp:3717 play_game

    {}
    th_a  common_api_client.cpp:7978 game_play

    {"command":"game_play"}
    th_a  cli.cpp:626 execute_command

@hackfisher
Copy link
Author

The "undefined:0" error is very similar to this:

http://grokbase.com/t/gg/nodejs/151dgk6zrv/missing-stack-in-uncaught-exception

@clar
Copy link

clar commented Oct 15, 2015

Some observation:

  1. the play command can work when it's not connected to the network, the difference might be there is no new_block coming.
  2. the isolate seems broken in play(), as it's failed to execute sample js script.

@hackfisher
Copy link
Author

I did not notice the first case you mentioned, The game_play command if for creating a transaction for play specific game, during the creation of the transaction it will call the contract javascript API "play", where the crash happens.

For the second case, yes, that also what I noticed so far, but I cannot understand why.

@clar
Copy link

clar commented Oct 29, 2015

Update:
This issue might be due to the facts that

  1. the isolate is created and used in different fibers, though these fibers are in the same thread, but they have their own stack and storage
  2. in V8, each thread has a PerIsolateThreadData instance for each isolate that it has entered,
    while this threadData will become invalid after switching to a new fiber

@clar
Copy link

clar commented Oct 30, 2015

we may can reset the stack limit size to bypass it, i'll test it soon.

clar added a commit that referenced this issue Oct 31, 2015
clar added a commit that referenced this issue Nov 20, 2015
@hackfisher
Copy link
Author

Do we still need the stack reset codes in:

ce74b52

@hackfisher
Copy link
Author

bitsuperlab/fc@9df6f00

@hackfisher
Copy link
Author

d1e834e

@clar
Copy link

clar commented Mar 7, 2016

"cucumber features/play_dice.feature" is passed, so I think this issue is fixed now.
But I do find a problem that delegate will crash when wallet_gia_create is called from alice node.
I'll track it in another issue.

@clar
Copy link

clar commented Mar 7, 2016

#170

@clar clar closed this as completed Mar 7, 2016
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

2 participants