Migrator problem with connection

Hi.

I have a strange exception while Migrator is working. I had read that this is something related to closing connection by the server.

Exception in thread "main" com.mongodb.MongoSocketWriteException: Exception sending message
	at com.mongodb.internal.connection.InternalStreamConnection.translateWriteException(InternalStreamConnection.java:541)
	at com.mongodb.internal.connection.InternalStreamConnection.sendMessage(InternalStreamConnection.java:429)
	at com.mongodb.internal.connection.InternalStreamConnection.sendCommandMessage(InternalStreamConnection.java:269)
	at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:253)
	at com.mongodb.internal.connection.UsageTrackingInternalConnection.sendAndReceive(UsageTrackingInternalConnection.java:99)
	at com.mongodb.internal.connection.DefaultConnectionPool$PooledConnection.sendAndReceive(DefaultConnectionPool.java:444)
	at com.mongodb.internal.connection.CommandProtocolImpl.execute(CommandProtocolImpl.java:72)
	at com.mongodb.internal.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:200)
	at com.mongodb.internal.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:269)
	at com.mongodb.internal.connection.DefaultServerConnection.command(DefaultServerConnection.java:131)
	at com.mongodb.operation.MixedBulkWriteOperation.executeCommand(MixedBulkWriteOperation.java:419)
	at com.mongodb.operation.MixedBulkWriteOperation.executeBulkWriteBatch(MixedBulkWriteOperation.java:257)
	at com.mongodb.operation.MixedBulkWriteOperation.access$700(MixedBulkWriteOperation.java:68)
	at com.mongodb.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:201)
	at com.mongodb.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:192)
	at com.mongodb.operation.OperationHelper.withReleasableConnection(OperationHelper.java:424)
	at com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:192)
	at com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:67)
	at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:193)
	at com.mongodb.client.internal.MongoCollectionImpl.executeBulkWrite(MongoCollectionImpl.java:467)
	at com.mongodb.client.internal.MongoCollectionImpl.bulkWrite(MongoCollectionImpl.java:447)
	at mflix.Migrator.main(Migrator.java:140)
Caused by: javax.net.ssl.SSLException: Broken pipe (Write failed)
	at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:127)
	at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:320)
	at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:263)
	at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:258)
	at java.base/sun.security.ssl.SSLSocketImpl$AppOutputStream.write(SSLSocketImpl.java:1016)
	at com.mongodb.internal.connection.SocketStream.write(SocketStream.java:99)
	at com.mongodb.internal.connection.InternalStreamConnection.sendMessage(InternalStreamConnection.java:426)
	... 20 more
	Suppressed: java.net.SocketException: Broken pipe (Write failed)
		at java.base/java.net.SocketOutputStream.socketWrite0(Native Method)
		at java.base/java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:110)
		at java.base/java.net.SocketOutputStream.write(SocketOutputStream.java:150)
		at java.base/sun.security.ssl.SSLSocketOutputRecord.encodeAlert(SSLSocketOutputRecord.java:81)
		at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:351)
		... 25 more
Caused by: java.net.SocketException: Broken pipe (Write failed)
	at java.base/java.net.SocketOutputStream.socketWrite0(Native Method)
	at java.base/java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:110)
	at java.base/java.net.SocketOutputStream.write(SocketOutputStream.java:150)
	at java.base/sun.security.ssl.SSLSocketOutputRecord.deliver(SSLSocketOutputRecord.java:320)
	at java.base/sun.security.ssl.SSLSocketImpl$AppOutputStream.write(SSLSocketImpl.java:1011)
	... 22 more    indent preformatted text by 4 spaces

[main] INFO org.mongodb.driver.connection - Closed connection [connectionId{localValue:4, serverValue:464799}] to mflix-shard-00-01-l4viq.mongodb.net:27017 because there was a socket exception raised by this connection.

Do you know how to resolve this problem?

As you mentioned, this is connection issue. Can you make sure that your system is able to connect to the cluster? Check for VPN/firewalls.

Also, check the host in migration file if that has anything wrong.

Kanika

Connection is ended by the server. I had no problem with previous tasks so this is not a problem with my part. Additionally, I have run tests from ConnectionTest class and all tests were finished wit success. What more can be done?

Hi @Michal_56787,

I have sent a message asking for code. :slight_smile:

Kanika

hi @kanikasingla I got the same issue, this is my code, please help
String mongoUri = “mongodb+srv://m220student:faked@cluster0-qubxy.gcp.mongodb.net/sample_mflix?retryWrites=true&w=majority”;
// instantiate database and collection objects
MongoDatabase mflix = MongoClients.create(mongoUri).getDatabase(“sample_mflix”);
MongoCollection movies = mflix.getCollection(“movies”);
Bson dateStringFilter = and( exists(“lastupdated”), type(“lastupdated”, “string”) );
String datePattern = “yyyy-MM-dd HH:mm:ss”;

    // documents that are required to be updated and the correct date
    // format pattern
    Document queryFilter = new Document();
    SimpleDateFormat dateFormat = new SimpleDateFormat(datePattern);

    // create list of bulkWrites to be applied.
    List<WriteModel<Document>> bulkWrites = new ArrayList<>();

    // iterate over the documents and apply the transformations.
    for (Document doc : movies.find(dateStringFilter)) {

        // Apply lastupdate string to date conversion
        WriteModel<Document> updateDate = transformDates(doc, dateFormat);
        if (updateDate != null) {
            bulkWrites.add(updateDate);
        }
    }

    // TODO> Ticket: Migration - create a query filter that finds
    // documents where `imdb.rating` is of type string
    Bson ratingStringFilter = and( exists("imdb.rating"), type("imdb.rating", "string") );
    for (Document doc : movies.find(ratingStringFilter)) {
        // Apply "imdb.rating" string to number conversion
        WriteModel<Document> updateRating = transformRating(doc);
        if (updateRating != null) {
            bulkWrites.add(updateRating);
        }
    }

    // execute the bulk update
    // TODO> Ticket: Migration - set the bulkWrite options
    BulkWriteOptions bulkWriteOptions = new BulkWriteOptions().ordered(false);
    if (bulkWrites.isEmpty()) {
        System.out.println("Nothing to update!");
        System.exit(0);
    }

    BulkWriteResult bulkResult = movies.bulkWrite(bulkWrites, bulkWriteOptions);
    // output the number of updated documents
    System.out.println(
        MessageFormat.format("Updated {0} documents", bulkResult.getModifiedCount()));
}

Following up here:

Kanika