Skip to content

Enable DomainSocket support for both mysql and postgresql #176

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

Closed
wants to merge 2 commits into from

Conversation

andy-yx-chen
Copy link
Contributor

No description provided.

@codecov
Copy link

codecov bot commented Jan 3, 2020

Codecov Report

Merging #176 (1401cd3) into master (082aa68) will decrease coverage by 0.10%.
The diff coverage is 50.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #176      +/-   ##
============================================
- Coverage     80.21%   80.10%   -0.11%     
- Complexity     1022     1023       +1     
============================================
  Files           258      258              
  Lines          3740     3745       +5     
  Branches        466      469       +3     
============================================
  Hits           3000     3000              
- Misses          541      542       +1     
- Partials        199      203       +4     
Impacted Files Coverage Δ
...async/sql/db/mysql/codec/MySQLConnectionHandler.kt 81.48% <33.33%> (-0.97%) ⬇️
...db/postgresql/codec/PostgreSQLConnectionHandler.kt 82.17% <33.33%> (-1.83%) ⬇️
...n/java/com/github/jasync/sql/db/util/NettyUtils.kt 63.63% <50.00%> (-1.37%) ⬇️
...ain/java/com/github/jasync/sql/db/Configuration.kt 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 082aa68...1401cd3. Read the comment docs.

@github-actions
Copy link

Stale pull request message

@royneely
Copy link

Huge thanks to the author of this PR (@andy-yx-chen). This saved my tail yesterday. 🙏

I'm under a tight deadline to finish an app and yesterday (a few days before deadline) I think to myself "I should probably test the deployment to make sure everything works". You know get the DNS straightened out and whatnot. Anyways, I'm planning to deploy my app on GCP via cloud run and connect to cloud sql. Turns out GCP ONLY supports unix socket connection in their serverless environment stuff. I spent almost all of yesterday googling ways around this because jasync does not currently support unix sockets. Turns out the only way around this is to use a private IP / VPC network with a "VPC serverless connector" that costs between $12 and $70 a month (no thanks). Felt like I was hosed. Would either have to rewrite my entire data layer to use hikari or some shit (gross). Or my expected server costs would rise by ~$600 a year just so I could connect to a stupid database (also gross).

ANYWAYS, I found this PR from issue #175, and was able to cobble together a solution that allowed me to use unix sockets. So, I'm now using jasync in production with GCP unix sockets and things are working great so far. Thanks!!

Will explain my solution for any poor soul who was in my predicament yesterday.

  1. fork jasync repo and apply these changes to new branch in forked repo (see https://github.com/eveyneely/jasync-sql/pull/1/files for my final change list)
  2. use jitpack to point to your newly forked (and updated) repo instead of maven for jasync https://jitpack.io/
  3. update application code to use unix socket instead of host when doing your database connection
fun dbConnectionPool(config: DbConfig): SuspendingConnection {
    return PostgreSQLConnectionBuilder.createConnectionPool {
        if (config.host != null) {
            host = config.host
        }
        database = config.database
        username = config.user
        password = config.password

        if (config.unixSocketFile != null) {
            unixSocket = DomainSocketAddress(config.unixSocketFile)
        }
    }.asSuspending
}

(in GCP the config.unixSocketFile would be the string /cloudsql/<YOUR CONNECTION NAME>/.s.PGSQL.5432)

I needed to import netty into my app just to use the DomainSocketAddress class (I used netty-all but I'm sure there's a better subpackage I should be using instead. Or maybe jaysc can export that one class as part of its api. I forget how that all works.)

Anyways I fired it up and crossed my fingers. And what-do-you-know, works like a charm. ✨

Thanks again to the author of this PR. If I ever get some time, I am going to try to come back submit a real PR.
Just wanted to leave this here for anyone else stuck in the same boat I was in yesterday.

@oshai
Copy link
Contributor

oshai commented Jun 20, 2021

Thanks for posting that here. A PR in the future will be awesome!
IIRC the main issue was testing it (in CI).

@czp3009
Copy link
Contributor

czp3009 commented Jan 16, 2022

why this awesome PR not merged? we really need it!

@oshai
Copy link
Contributor

oshai commented Jan 16, 2022

I can reopen this if you would like. the original reason for not having this merged was lack of testing: #175 (comment)

@oshai oshai reopened this Jan 16, 2022
@czp3009
Copy link
Contributor

czp3009 commented Jan 16, 2022

@oshai Thanks your response!

The feature of unix domain socket is too important(e.g. in GCP AppEngine), I will review the code and resubmit a PR if i can.

@oshai
Copy link
Contributor

oshai commented Jan 16, 2022

@oshai Thanks your response!

The feature of unix domain socket is too important(e.g. in GCP AppEngine), I will review the code and resubmit a PR if i can.

Thank you!

@czp3009 czp3009 mentioned this pull request Feb 13, 2022
@oshai
Copy link
Contributor

oshai commented Oct 12, 2022

Implemented in #319

@oshai oshai closed this Oct 12, 2022
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.

4 participants