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

[#2156] Replace variable length arrays with alloca() (main) #2181

Merged
merged 1 commit into from May 24, 2024

Conversation

SwooshyCueb
Copy link
Member

@SwooshyCueb SwooshyCueb commented Mar 7, 2024

Addresses #2156 (for real this time)

Copy link
Contributor

@korydraughn korydraughn left a comment

Choose a reason for hiding this comment

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

The changes look fine, but I'm not sold on the use of alloca yet.

I don't have any experience with it, but reading about it indicates we should probably rethink using it.

The main thing is that we're replacing VLAs with alloca, which seems incorrect.

Thoughts?

@SwooshyCueb
Copy link
Member Author

I'm not sure I understand the problem. alloca() allocates on the stack, just as a VLA does.

@korydraughn
Copy link
Contributor

Right. I'm concerned about stack overflow and undefined behavior.

From alloca's man page (https://man7.org/linux/man-pages/man3/alloca.3.html):

The alloca() function returns a pointer to the beginning of the
allocated space.  If the allocation causes stack overflow,
program behavior is undefined.

The amount of stack space needed is unknown for the some/all of the VLAs.

Here's another link on it: https://stackoverflow.com/a/1018865/5818611

Another thing that comes to mind is if something weird happens as a result of using alloca, will we be able to track down the cause?

@korydraughn
Copy link
Contributor

The NOTES section of the man page makes me slightly nervous too.

@SwooshyCueb
Copy link
Member Author

Looking at the comments in the stackoverflow answer you linked, it appears that VLAs have the exact same problems as alloca() in regards to stack overflows.

What do you find concerning in the NOTES section?

@korydraughn
Copy link
Contributor

That section states its use is discouraged. I take that as the dev must be sure that function is the correct choice for the task and it doesn't leave room for stack overflow.

@SwooshyCueb
Copy link
Member Author

If my understanding is correct, given our usage, if a stack overflow would occur with alloca(), it would occur with VLAs as well. Therefore, if we have a potential stack overflow issue, we had it prior to this PR. The case can certainly be made that we should not be allocating space on the stack at runtime like this in the first place, but that's outside the scope of this PR.

@korydraughn
Copy link
Contributor

That's a fair point.

Please run the test suite to confirm everything is still good.

@SwooshyCueb
Copy link
Member Author

All tests fail for tip of main, so they fail here too.

@korydraughn
Copy link
Contributor

That's unexpected.

Was anything reported that indicates the reason for the failures?
Does it fail at the same place / in the same way on every run?

@SwooshyCueb
Copy link
Member Author

So I forgot that the testing environment will report that all tests fail for plugin tests regardless of how many actually fail, and it turns out that on tip of main, only most tests fail. I think it may have something to do with irods/irods#7502. I'll open an issue about that.

For this PR, all tests did actually fail, and it appeared to be due to a signature mismatch. I figured out that this was due to a difference in how sizeof() works with alloca() vs VLAs, so I've replaced the relevant instances of sizeof() (see the new [SQUASH] commit), and now the test failures match tip of main.

I don't like clang-format's suggestion for the canonicalRequestLen definition, so I'm ignoring it.

@korydraughn
Copy link
Contributor

and now the test failures match tip of main.

Are the failing tests you're referring to part of the irods/irods test suite or this repo's test suite?

I don't like clang-format's suggestion for the canonicalRequestLen definition, so I'm ignoring it.

Agreed. Wrap it in // clang-format off/on so future edits don't yell at us about it.

@SwooshyCueb
Copy link
Member Author

Are the failing tests you're referring to part of the irods/irods test suite or this repo's test suite?

They're all from this repo

@korydraughn
Copy link
Contributor

Are the tests that fail expected? I don't remember that being the case.

@SwooshyCueb
Copy link
Member Author

I don't think so. I think they're failing because they weren't updated to expect the deprecation message introduced in irods/irods#7502. I'm still looking into it. There may be other tests failing for different reasons.

@korydraughn
Copy link
Contributor

Got it. Will come back once you've learned more.

@SwooshyCueb
Copy link
Member Author

SwooshyCueb commented Mar 11, 2024

Changing the tests to expect the deprecation message fixed some of them, but another one, test_irods_resource_plugin_s3_minio.Test_Compound_With_S3_Resource.test_irepl_multithreaded fails for what seems to be an unrelated reason, and leaves the server in a state that causes every subsequent test to fail. This test is inherited from ResourceBase in the irods repo. I'll open another issue for this.

@SwooshyCueb SwooshyCueb changed the title [#2156,#2180] Replace variable length arrays with alloca(), and add missing curl include to request_context.h (main) [#2156,#2180,#2183] Replace variable length arrays with alloca(), and add missing curl include to request_context.h, and fix some tests (main) Mar 12, 2024
@SwooshyCueb
Copy link
Member Author

I've opened #2184 to cover the remaining test failures. The cause of the failure wasn't evident to me so I'm going to leave that work to someone else so I can get back to working on buildsystem and packaging stuff.

@SwooshyCueb
Copy link
Member Author

If there are no objections, I'm going to # this and the 4-3-stable PR

Copy link
Contributor

@alanking alanking left a comment

Choose a reason for hiding this comment

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

I think I'm okay with the changes since alloca presents nothing more dangerous than VLAs. I just saw one thing in the tests.

Deferring to @korydraughn, though.

packaging/test_irods_resource_plugin_s3_for_cloudian.py Outdated Show resolved Hide resolved
@korydraughn
Copy link
Contributor

Let's hold on pounding. We need to determine why the tests are failing. Once that's handled we can proceed.

@SwooshyCueb SwooshyCueb changed the title [#2156,#2180,#2183] Replace variable length arrays with alloca(), and add missing curl include to request_context.h, and fix some tests (main) [#2156] Replace variable length arrays with alloca() (main) Apr 27, 2024
@SwooshyCueb
Copy link
Member Author

SwooshyCueb commented Apr 27, 2024

We merged the test and include fixes in a separate PR (#2189, #2190) so they could make it in for 4.3.2. They've been removed from this PR (and the 4-3-stable PR).

@trel
Copy link
Member

trel commented Apr 29, 2024

Going to wait until after 4.3.2 to merge this PR.

@SwooshyCueb
Copy link
Member Author

I've confirmed that tests pass now. If there are no objections, I will # this PR and the 4-3-stable PR.

Copy link
Contributor

@korydraughn korydraughn left a comment

Choose a reason for hiding this comment

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

Pound it.

@SwooshyCueb
Copy link
Member Author

#'d

@alanking alanking merged commit f3e6850 into irods:main May 24, 2024
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants