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

RUBY-986 Fallback to IPv4 if IPv6 isn't supported #660

Merged
merged 1 commit into from Jul 23, 2015
Merged

RUBY-986 Fallback to IPv4 if IPv6 isn't supported #660

merged 1 commit into from Jul 23, 2015

Conversation

agis
Copy link
Contributor

@agis agis commented Jul 22, 2015

Prior to this change, if the provided server address resolved to IPv6
but the mongo server wasn't configured for IPv6, the client would
continuously attempt to connect to the IPv6 address until the
server_selection_timeout was hit and never fallback to IPv4.

This fixes the behavior to try all the different protocol families in
the list.

Fixes https://jira.mongodb.org/browse/RUBY-986.

@estolfo
Copy link
Contributor

estolfo commented Jul 22, 2015

Thanks @agis-
Is there any chance you could provide a test as well? Thanks

@agis
Copy link
Contributor Author

agis commented Jul 22, 2015

@estolfo Sure, will add them in a bit.

@agis agis changed the title Actually try different families protocol families Actually try different protocol families Jul 22, 2015
@agis agis changed the title Actually try different protocol families RUBY-986 Try different protocol families on connection refuse Jul 22, 2015
@agis agis changed the title RUBY-986 Try different protocol families on connection refuse RUBY-986 Fallback to IPv4 if IPv6 isn't supported Jul 22, 2015
@agis
Copy link
Contributor Author

agis commented Jul 22, 2015

@estolfo added a test case.

I've also refactored the code to make it easier to follow; let me know if you still prefer the initial version instead.

@estolfo
Copy link
Contributor

estolfo commented Jul 23, 2015

Thanks!

@estolfo
Copy link
Contributor

estolfo commented Jul 23, 2015

Looks good, thanks so much!

This is minor, but would you mind changing the test a little to match our formatting for consistency? Putting the 'allow' portion in a before block and check that address.socket returns an object would be great:

  describe "#socket" do

    context 'when providing a DNS entry that resolves to both IPv6 and IPv4' do

      let(:address) do
        described_class.new('localhost:27017')
      end

      before do
        allow(::Socket).to receive(:getaddrinfo).and_return(
          [ ["AF_INET6", 0, "::1", "::1", ::Socket::AF_INET6, 1, 6],
            ["AF_INET", 0, "127.0.0.1", "127.0.0.1", ::Socket::AF_INET, 1, 6]]
        )
      end

      it "attempts to use IPv6 and fallbacks to IPv4" do
        expect(address.socket(0.0)).not_to be_nil
      end
    end
  end

@agis
Copy link
Contributor Author

agis commented Jul 23, 2015

Sure, updated! :)

@estolfo
Copy link
Contributor

estolfo commented Jul 23, 2015

If you could just rebase against master so we can make sure tests pass, I can merge it. Thanks!

@agis
Copy link
Contributor Author

agis commented Jul 23, 2015

Rebased.

Prior to this change, if the provided server address resolved to IPv6
but the mongo server wasn't configured for IPv6, the client would
continuously attempt to connect  to the IPv6 address until the
server_selection_timeout was hit and never fallback to IPv4.

This fixes the behavior to try all the different protocol families in
the list.

Fixes https://jira.mongodb.org/browse/RUBY-986.
@estolfo
Copy link
Contributor

estolfo commented Jul 23, 2015

The travis failures are unrelated. I'll merge this now, thanks again!

estolfo added a commit that referenced this pull request Jul 23, 2015
RUBY-986 Fallback to IPv4 if IPv6 isn't supported
@estolfo estolfo merged commit 150f848 into mongodb:master Jul 23, 2015
@agis agis deleted the protocol-family-fallback branch July 23, 2015 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants