Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Fix dumping on exit #337

Merged
merged 7 commits into from
Nov 15, 2022
Merged

Fix dumping on exit #337

merged 7 commits into from
Nov 15, 2022

Conversation

mikiw
Copy link
Contributor

@mikiw mikiw commented Nov 10, 2022

Usage related changes

  • Quick fix for double execution of dump function.

Development related changes

  • test_dumping_on_exit updated to cover scenario with call after load

Checklist:

  • Applied formatting - ./scripts/format.sh
  • No linter errors - ./scripts/lint.sh
  • Performed code self-review
  • Rebased to the last commit of the target branch (or merged it into my branch)
  • Documented the changes
  • Linked the issues which this PR resolves
  • Updated the tests
  • All tests are passing

@mikiw mikiw marked this pull request as draft November 10, 2022 09:30
@mikiw
Copy link
Contributor Author

mikiw commented Nov 10, 2022

The second dump was performed with a clean instance of starknet which means that this functionality didn't work at all.

This is related to the introduction of GunicornServer and the number of workers:

    asyncio.run(state.starknet_wrapper.initialize())

    try:
        print(f" * Listening on https://{args.host}:{args.port}/ (Press CTRL+C to quit)")
        pid = os.getpid()
        GunicornServer(app, args).run()
    except KeyboardInterrupt:
        pass
    finally:
        if args.dump_on == DumpOn.EXIT and os.getpid() != pid:
            state.dumper.dump()
            sys.exit(0)

Although a new test was introduced and a quick fix was made it seems that it's a hack, not a real solution.

After starting a starknet devnet there are 2 processes an instance of GunicornServer and 1 worker. The GunicornServer instance has an empty devnet and the worker has a real instance with blocks.

The number of processes is equal to the count of workers + 1.
image

For example, if we increase the number of workers from 1 to 2 test will fail.

@mikiw
Copy link
Contributor Author

mikiw commented Nov 10, 2022

@Solpatium do you have any idea how to fix it properly?

@mikiw mikiw linked an issue Nov 10, 2022 that may be closed by this pull request
@FabijanC FabijanC changed the title Dump on exit Fix dumping on exit Nov 10, 2022
@FabijanC
Copy link
Collaborator

starknet_devnet/server.py Outdated Show resolved Hide resolved
starknet_devnet/server.py Show resolved Hide resolved
starknet_devnet/server.py Outdated Show resolved Hide resolved
@mikiw
Copy link
Contributor Author

mikiw commented Nov 10, 2022

Should we use worker_exit in gunicorn and always use 1 worker?

Add to config:

self.cfg.set("worker_exit", worker_exit)

Example:

def worker_exit(server, worker):
    try:
        print("worker_exit", os.getpid())
        state.dumper.dump()
        sys.exit(0)
    except:
        pass

@Solpatium
Copy link
Contributor

Having more than 1 worker doesn't make sense at the moment as there is no way of sharing the state between them, right?

@FabijanC
Copy link
Collaborator

Having more than 1 worker doesn't make sense at the moment as there is no way of sharing the state between them, right?

Yes. If you don't have objections, I'll merge the PR as it currently is.

@FabijanC FabijanC marked this pull request as ready for review November 14, 2022 10:57
@FabijanC FabijanC merged commit 2979e80 into master Nov 15, 2022
@FabijanC FabijanC deleted the dump-on-exit branch November 15, 2022 11:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dumping doesn't work with --dump-on exit
3 participants