Skip to content

MINIFICPP-1263 - Fix for segfault#818

Closed
adamdebreceni wants to merge 4 commits intoapache:masterfrom
adamdebreceni:MINIFICPP-1263
Closed

MINIFICPP-1263 - Fix for segfault#818
adamdebreceni wants to merge 4 commits intoapache:masterfrom
adamdebreceni:MINIFICPP-1263

Conversation

@adamdebreceni
Copy link
Contributor

Thank you for submitting a contribution to Apache NiFi - MiNiFi C++.

In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:

For all changes:

  • Is there a JIRA ticket associated with this PR? Is it referenced
    in the commit message?

  • Does your PR title start with MINIFICPP-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.

  • Has your PR been rebased against the latest commit within the target branch (typically master)?

  • Is your initial contribution a single, squashed commit?

For code changes:

  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?
  • If applicable, have you updated the LICENSE file?
  • If applicable, have you updated the NOTICE file?

For documentation related changes:

  • Have you ensured that format looks appropriate for the output in which it is rendered?

Note:

Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.


assert(LogTestController::getInstance().contains("HTTP operation timed out, with absolute timeout 3000ms"));

delete server;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why does leaking it cause segfault?

Btw I think unique_ptr would be a nicer solution.

Copy link
Contributor Author

@adamdebreceni adamdebreceni Jun 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was just a temporary check, in no way did I intend it to be the solution

the segfault was (probably) caused by the CivetServer creating a load of threads and we just exited main like there is no tomorrow

@adamdebreceni adamdebreceni changed the title WIP - MINIFICPP-1263 - Possible fix for segfault MINIFICPP-1263 - Possible fix for segfault Jun 23, 2020
}
}
~CivetLibrary() {
if (--getCounter() == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the motivation behind using a getter on our own private member?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will make the getCounter static, we do not access a member though this getter, but a static library initialization counter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


return server;
void addHandler(const std::string& uri, CivetHandler* handler) {
handlers_.emplace_back(handler);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only fancy, but I prefer not to use emplace when inserting already existing objects as emplace calls explicit ctors as well and it's very easy to point the gun against ourselves.

Copy link
Contributor Author

@adamdebreceni adamdebreceni Jun 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good advice, done

stop_signal_.wait_for(lock, time, [&] {return terminate_.load();});
}

bool isServerRunning() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fancy: const

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


}
TestServer(std::string &port, std::string &rooturi, CivetHandler *handler) {
const char *options[] = {"document_root", ".", "listening_ports", port.c_str(), 0};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is old code, but as far as I see we could simply pass and std::vectorstd::string to Civetweb's ctor, so this could be something like:

std::vector<std::string> options = {"document_root", ".", "listening_ports", port};
server_ = utils::make_unique<CivetServer>(options);

The same applies to the above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@adamdebreceni adamdebreceni changed the title MINIFICPP-1263 - Possible fix for segfault MINIFICPP-1263 - Fix for segfault Jun 24, 2020
Copy link
Contributor

@arpadboda arpadboda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@arpadboda arpadboda closed this in e26d391 Jun 24, 2020
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

Successfully merging this pull request may close these issues.

3 participants