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

kn: checksum bindings #1182

Open
wants to merge 23 commits into
base: kn-main
Choose a base branch
from
Open

kn: checksum bindings #1182

wants to merge 23 commits into from

Conversation

lauzadis
Copy link
Contributor

Issue #

Description of changes

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@lauzadis lauzadis marked this pull request as ready for review November 19, 2024 16:12
@lauzadis lauzadis requested a review from a team as a code owner November 19, 2024 16:12
Comment on lines +105 to +106
if not opts.no_system_certs:
cmd.append(f'-v/etc/ssl:/etc/ssl')
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: f is unnecessary since we're not formatting any parameters in this string

Comment on lines -22 to +21
protected val serverPort: Int = ServerSocket(0).use { it.localPort }
protected val serverPort: Int = 54734
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: This will conflict if any other process (including a parallel build of this package in another workspace) is using port 54734. Is there a reason why it's necessary to use a static port?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we don't configure a port, it will default to 80, we could make it a randomly selected port if you think that will be safer?

Copy link
Contributor

Choose a reason for hiding this comment

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

Random ports are marginally safer but still could conflict with an open port. I think we can still bind to an available address using Ktor's low-level KMP socket interfaces:

protected val serverPort: Int = runBlocking {
    SelectorManager(coroutineContext).use { selector ->
        aSocket(selector)
            .tcp()
            .bind()
            .use { (it.localAddress as InetSocketAddress).port }
    }
}

Comment on lines 32 to -44
attempt++
try {
server.start()
println("test server listening on: $testHost:$serverPort")
break
} catch (cause: Throwable) {
if (attempt >= 10) throw cause
Thread.sleep(250L * attempt)
delay(250L * attempt)
}
} while (true)

ensureServerRunning()
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Isn't server.start() asynchronous? Won't removing ensureServerRunning() mean that it's possible to return from this method before the server is actually running?

Comment on lines 22 to 23
crc.update(input.encodeToByteArray(), 0, input.length)
assertEquals(2666930069U, crc.digestValue()) // checksum of "foobar"
assertEquals("nvYflQ==", crc.digest().encodeBase64String())
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Why are we moving the digestValue checks from these tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Our current JVM implementation of digestValue() does not reset the checksum and these tests were depending on that faulty behavior (calling digestValue() then digest() immediately after).

I've clarified the behavior in KDocs and also updated our JVM implementation. Let me know if you think we should keep the existing (arguably broken) behavior. KotlinNative / CRT will likely be unable to match that behavior though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see. If this was already broken behavior then you're probably right.

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.

2 participants