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

Merge: Always initialize LibGit #3221

Merged
merged 2 commits into from Nov 16, 2019

Conversation

dominicjaeger
Copy link
Contributor

Should fix #3206

This is required by their documentation. This certainly gives us memleaks but
avoids segfaults.

Basics

These points need to be fulfilled for every PR:

  • Short descriptions of your changes are in the release notes
    (added as entry in doc/news/_preparation_next_release.md which
    contains _(my name)_)
    Please always add something to the release notes.
  • Details of what you changed are in commit messages
    (first line should have module: short statement syntax)
  • References to issues, e.g. close #X, are in the commit messages.
  • The buildservers are happy.
  • The PR is rebased with current master.

If you have any troubles fulfilling these criteria, please write
about the trouble as comment in the PR. We will help you.
But we cannot accept PRs that do not fulfill the basics.

Checklist

Check relevant points but please do not remove entries.
For docu fixes, spell checking, and similar none of these points below
need to be checked.

  • I added unit tests for my code
  • I fully described what my PR does in the documentation
    (not in the PR description)
  • I fixed all affected documentation
  • I added code comments, logging, and assertions as appropriate (see Coding Guidelines)
  • I updated all meta data (e.g. README.md of plugins and METADATA.ini)
  • I mentioned every code not directly written by me in THIRD-PARTY-LICENSES

Review

Reviewers will usually check the following:

Labels

If you are already Elektra developer:

  • Add the "work in progress" label if you do not want the PR to be reviewed yet.
  • Add the "ready to merge" label if the basics are fulfilled and you also
    say that everything is ready to be merged.

This is required by their documentation. This certainly gives us memleaks but
avoids segfaults.
@dominicjaeger dominicjaeger self-assigned this Nov 15, 2019
@dominicjaeger dominicjaeger added this to In progress in Improve 3-way merge via automation Nov 15, 2019
@dominicjaeger dominicjaeger mentioned this pull request Nov 15, 2019
ELEKTRA_LOG ("cmerge can use libgit2 to handle arrays");
if (handleArrays (ourCropped, theirCropped, baseCropped, result, informationKey, strategy) > 0)
{
ksDel (result);
return NULL;
}
#ifndef CMERGE_ON_LINUX
git_libgit2_shutdown ();
Copy link
Member

Choose a reason for hiding this comment

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

Why do we do the init but no shutdown here?
Btw if it is definitely an upstream problem/leak we can make a valgrind suppression for it and report the issue there.

Copy link
Contributor

Choose a reason for hiding this comment

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

Some libraries are not safe to be initialized again after shutdown. Furthermore we do not really know if anybody else is using libgit2 in our process. So it can make sense to not call shutdown (if it is not working properly).

The whole global init and shutdown is calling for a lot of trouble. Unfortunately, many libraries do not use proper solutions (like handles).

In theory (with mutex protection and ref counting) multiple init/shutdown could be supported but it is rare that this is working properly.

and report the issue there

I agree.

Copy link
Member

Choose a reason for hiding this comment

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

Some libraries are not safe to be initialized again after shutdown.

Ok, but the shutdown was clearly called before, and now we only call init. I assumed it was removed by mistake. If there is a reason not to call it, I'm fine with that!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why do we do the init but no shutdown here?

That was a mistake :/ Nonetheless, it is actually optional

Usually you don’t need to call the shutdown function as the operating system will take care of reclaiming resources, but if your application uses libgit2 in some areas which are not usually active, you can use git_libgit2_shutdown(); to ask the library to clean up the global state. (source)


Btw if it is definitely an upstream problem/leak we can make a valgrind suppression for it

I added memleak labels for both tests in this PR.

and report the issue there.

The person who answered my stackoverflow question also appears in the LibGit2 contributor list, so I assume they are aware.

Copy link
Contributor

Choose a reason for hiding this comment

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

I added memleak labels for both tests in this PR.

It is better if we suppress everything from libgit. This way we still check if our code has memleaks.

The person who answered my stackoverflow question also appears in the LibGit2 contributor list, so I assume they are aware.

You never know. Better we report it. But they are obviously only interested in the latest versions, maybe they already fixed it?

@dominicjaeger
Copy link
Contributor Author

It is better if we suppress everything from libgit. This way we still check if our code has memleaks.

Those memleak labels are already in #3209 btw.

It is better if we suppress everything from libgit.

I don't know how (yet).

But they are obviously only interested in the latest versions, maybe they already fixed it?

This is why I'd prefer to test with their latest version first and report afterwards if necessary.

@markus2330 What is higher priority: Stuff like tool integration for the merge library #3131 or this? I don't mind spending time on researching this further, but there is not too much time left until December.

@markus2330
Copy link
Contributor

markus2330 commented Nov 16, 2019

I don't know how (yet).

valgrind --gen-suppressions and add this to tests/valgrind.suppression

Stuff like tool integration for the merge library #3131 or this?

It should not segfault and should work reliable. If it does not segfault, of course tool integration is more important than valgrind supressions.

So you are right, maybe having memleak label is a good solution.

@dominicjaeger
Copy link
Contributor Author

dominicjaeger commented Nov 16, 2019

I created a Fedora 31 VM and compiled this branch in it. Strangely enough some tests (e.g. base64, testscr_check_formatting, testscr_check_gen IIRC) randomly fail with make run_all. However, nothing seems related to merging and valgrind ./bin/test_cmerge exits successfully with 0 bytes in use at exit.

Therefore I am relatively sure that this PR really fixes #3220.

@markus2330 markus2330 merged commit fa5c1c5 into ElektraInitiative:master Nov 16, 2019
Improve 3-way merge automation moved this from In progress to Done Nov 16, 2019
@markus2330
Copy link
Contributor

Thank you!

I created a Fedora 31 VM [...] Strangely enough some tests (e.g. base64, testscr_check_formatting, testscr_check_gen IIRC) randomly

If you already created the VM: Can you check if one of them always fails? (And report if it is so.)

Therefore I am relatively sure that this PR really fixes #3220.

Ok. Just to be sure: when doing the cleanup there are also problems/crashes? Otherwise we should call the cleanup. (First I thought you removed it by purpose and I gave reasons why you may have done it. But later you said you removed it by accident.)

@dominicjaeger
Copy link
Contributor Author

Just to be sure: when doing the cleanup there are also problems/crashes?

I haven't tested out the effects of the library function actually... IIRC I always had the shutdown when I initialized it. Until yesterday night, when I accidentally removed the shutdown while keeping the initialization.

later you said

That was unfortunate because I started to answer before your answer was posted and I did not reload.

Nevertheless, both versions, shutting down and not shutting down should be OK according to the LibGit documentation.

@dominicjaeger dominicjaeger deleted the libgit branch November 16, 2019 14:03
@mpranj
Copy link
Member

mpranj commented Nov 16, 2019

@Chemin1 thank you!

Regarding the other problems: I use Fedora mainly and found no problems unique to the system. The usual suspects (dbusrecv, zeromq,..) can time out but this is not unique to Fedora.

Nevertheless it might be nice to add a Fedora docker image to the tests as the package versions are usually much newer than Debian.

@markus2330
Copy link
Contributor

Nevertheless it might be nice to add a Fedora docker image to the tests as the package versions are usually much newer than Debian.

Yes, I fully agree that it would be amazing to have Fedora docker images for our Jenkins tests.

@dominicjaeger
Copy link
Contributor Author

dominicjaeger commented Nov 16, 2019

All the errors that I got seem to really have been random. I just got three successful make run_all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants